Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Foreign Languages > German Forum
Home Register FAQ Members List Search Today's Posts Mark Forums Read


Client for MPD


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 03-04-2008, 10:14 AM
Knows the basics
 
Join Date: Mar 2008
Location: germany
Posts: 79
Default

Hi,
danke an alle.

Die Info war gut, denn MPD setzt für die Kommunuikation zwischen Client und
Server TCP als Übertragungsprotokoll ein. Somit kann ich vom Sofa aus meine
Stereoanlage fernsteuern und kann die Musik genießen ohne mich bewegen zu
müssen.

Gruß Mamuen
Reply With Quote
  #12 (permalink)  
Old 03-05-2008, 03:12 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 610
Default

Quote:
Originally Posted by alfcen View Post
Hier sind es 8 Stunden spaeter als bei Euch
... netter Trick: man zieht nach Okinawa und ist dann seiner (Ursprungs-)Zeit immer ein wenig voraus ...
Reply With Quote
  #13 (permalink)  
Old 03-05-2008, 04:12 PM
Knows the basics
 
Join Date: Mar 2008
Location: germany
Posts: 79
Default

Quote:
Originally Posted by specci48 View Post
... netter Trick: man zieht nach Okinawa und ist dann seiner (Ursprungs-)Zeit immer ein wenig voraus ...
Ok, Ok man kanns ja mal versuchen ;-)

Ich hab jetzt meine ersten gehversuche hinter mir. Auf meinem LinuxSoundserver
läuft der MPD-Dämon und mittels TCPDump überwache ich die WLanschnittstelle.

Nachdem ich eine Verbindung mittels meines Progs aufzubauen versuche, sehe
ich in TCPDump ein von mir gesendetes IP-Paket. Dieses wird mehrmals gesendet
aber es kommt zu keinem Verbindungsaufbau (3-Wegehandshake bei TCP). Die
Firewall ist ausgeschaltet. Per Webbrowser bekomme ich aber Zugriff auf die
Linuxbüchse.

Tja, da bleibt nur noch die eigene Unfähigkeit (Programmierkunst) übrig.
Ich versuch mal mein Prog anzuhängen und hoffe, dass einer einen Fehler
findet.

Gruß Mamuen
Attached Files
File Type: sbp test1.sbp (2.1 KB, 3 views)
Reply With Quote
  #14 (permalink)  
Old 03-06-2008, 04:41 PM
Knows the basics
 
Join Date: Mar 2008
Location: germany
Posts: 79
Default

Hi,

ich habe eine kleine Erfolgsmeldung zu berichten, nachdem ich den Port von 6600
auf 80 geändert habe, bekam ich keine Fehlermeldung mehr (Resssource konnte
nicht mehr gefunden werden). Statt dessen bekam ich natürlich Fehlermeldungen
von meinem Webserver.

Werde wohl noch ein Bischen mit dem Protokoll von MPD experimentieren
müssen.

Gruß mamue
Reply With Quote
  #15 (permalink)  
Old 03-09-2008, 06:18 AM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 19
Send a message via MSN to brathbone
Default

Forgive the response in english. I don't speak German, but I may be able to help.

MPD server listens on TCP port 6600

When you send commands, you must append CHR(13) to the end of the command.

Responses from MPD server will also be terminated with CHR(13)

I don't have MPD, so code below is untested.

Try something like this:

Sub Globals
Dim IP(0) As String
Dim bufferbits(0) As byte
End Sub

Sub ButtonConnect_Click

Dim IP(0) As String
IP() = Client.GetIP(textboxip.Text)
'client = network.dll client
client.Connect(IP(0),6600)
'stream = binaryfile object
stream.New1(client.GetStream,false)
label1.Text = "Connection established."
timer1.Enabled = true
'//issue the "next" command
stream.WriteBytes (stream.StringToBytes("next" & CHR(13)) )
End Sub

Sub Timer1_Tick
If client.DataAvailable = true Then
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buffer = bit.BytesToString(bufferbits(),0,count)
'show server response
label1.Text = buffer
End Sub

Best wishes,
__________________
Brian Rathbone

Laptop: AMD Turion 64 Mobile 2ghz, 2GB RAM, Dual GeForce Go 7900 GTX 768MB SLI, Dual 200GB HDD at RAID0. XP Pro sp2

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #16 (permalink)  
Old 03-09-2008, 09:46 AM
Knows the basics
 
Join Date: Mar 2008
Location: germany
Posts: 79
Default

Hi brathbone,

Thanke you for your interest. I have check it at
http://mpd.wikia.com/wiki/MusicPlaye...rotocolOutline

There you can read:
"The client transmits a command sequence, terminated by a newline."
"Each server response ends with a completion code. There are two codes: OK and ACK."

My problem is now, the prog. reads only about 33600 bytes not the whole stream.
By the next trasmitted newline the prog. will receive the rest.


Sub Globals
'Declare the global variables here.
Dim bufferbits(0) As byte
End Sub

Sub App_Start
Form1.Show
End Sub

Sub btnSetSRV_Click
bit.New1
client.New1
client.Connect ("192.168.200.1",6600)
stream.New1(client.GetStream,false)
Do While client.DataAvailable = false
Loop
Dim bufferbits(128) As byte
count = stream.ReadBytes(bufferbits(),128)
buffer = bit.BytesToString(bufferbits(),0,count)
txtAntwort.Text = buffer
Label5.Text = "Connected to 192.168.200.1:6600"
Form2.Show
End Sub

Sub btnSend_Click
stream.WriteBytes (stream.StringToBytes(txtBefehl.Text & Chr(10)) )
timer1.Enabled = true
End Sub

Sub Timer1_Tick
If client.DataAvailable = true Then
Dim bufferbits(102400) As byte
count = stream.ReadBytes(bufferbits(),102400)
buffer = bit.BytesToString(bufferbits(),0,count)
buffer = StrReplace (buffer,Chr(10),crlf) 'linefeed to crlf
txtAntwort.Text = buffer
txtcount.Text = count
End If
timer1.enabled = false
txtBefehl.Focus
End Sub

Sub btnExit_Click
client.Close
AppClose
End Sub



Best wishes, Mamuen
Reply With Quote
  #17 (permalink)  
Old 03-16-2008, 05:40 AM
brathbone's Avatar
Junior Member
 
Join Date: Feb 2008
Location: Rutherfordton, North Carolina
Posts: 19
Send a message via MSN to brathbone
Default

mamuen,

Thanks for reminding me that I have to be more careful about waiting for all the data to arrive.

So let's say the server sends two commands like:

220 then a bunch of other text & CRLF
240 something else & CRLF


We might get "220 then" when we check for incoming data, and then we might get "a bunch of other text" & chr(13) & chr(10) & "240 Something el"
and then might get "se" & chr(13) & chr(10) on our next check.

The trick here is going to be to use a global variable to store our incomplete commands between checking for data. Then when we check for data, we check to see if there is a terminator in it (chr(13) & chr(10)) using something like:

If StrIndexOf(stringbuffer,chr(13) & chr(10),0) > -1

We can't assume that the terminator is the last part of our data, since we may have received part of the next message as well, so if there is a terminator, take everything before the terminator, append it to whatever may have come in before (our global variable) and then act accordingly. Of course we need to look for additional terminators or partial data before proceeding.

If we don't have a terminator, then append the data to our global variable. I don't have this code written in Basic4PPC yet, but here is pseudo-code based on what my REALbasic code does:

count = stream2.ReadBytes(bufferbits(),8192)
stringbuffer = bit.BytesToString(bufferbits(),0,count)

'//look for a terminator in our new data
i = StrIndexOf(stringbuffer,CHR(13) & CHR(10),0)

if i > -1 then
'//loop though and process commands until we run out of terminators
do while i > -1

'//parse out everything before the first terminator
'//append it to any existing data in our global variable
'//process the command

'//look for additional terminators in existing data
i = StrIndexOf(stringbuffer,CHR(13) & CHR(10),i)
loop

else
'//no terminator in this batch of data
'//append text to global variable and wait for more data.

end if

hope that helps,
__________________
Brian Rathbone

Laptop: AMD Turion 64 Mobile 2ghz, 2GB RAM, Dual GeForce Go 7900 GTX 768MB SLI, Dual 200GB HDD at RAID0. XP Pro sp2

Device: Treo 750, WM6, 300mhz,128MB RAM, 2GB miniSD, 240x240 display
Reply With Quote
  #18 (permalink)  
Old 03-19-2008, 10:15 PM
Knows the basics
 
Join Date: Mar 2008
Location: germany
Posts: 79
Default

Hi brathbone,

your way i think is the clean way. I found a other solution (quick and dirty), but it works. The endstring of transmision is always "OK"+crlf.


endstr = 0
Dim bufferbits(4096) As byte
If client.DataAvailable = true Then
Do
count = stream.ReadBytes(bufferbits(),4096)
buffer = bit.BytesToString(bufferbits(),0,count)
buffer = StrReplace (buffer,Chr(10),crlf) 'linefeed to crlf

If SubString (buffer,StrLength(buffer)-4,2)="OK" Then
endstr = 1
Else If SubString (buffer,0,3)="ACK" Then
endstr = 2
End If

txtAntwort.Text = txtAntwort.Text & buffer
Loop While endstr = 0
txtcount.Text = endstr
End If



Regards manuen
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MPD client for Windows Mobil mamuen Open Source Projects 1 06-01-2008 12:21 PM
Use Network.Client to get the definition of a word from Dict.org brathbone Code Samples & Tips 9 03-09-2008 03:34 AM
FTP Client PatrikL Share Your Creations 2 05-05-2007 06:54 AM


All times are GMT. The time now is 07:53 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0