Results 1 to 11 of 11

Thread: server communication [resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283

    server communication [resolved]

    using telnet i can connect to this server (for the freedb music database)

    freedb.freedb.org [ port 8880 ]

    then i can type the command "sites" to get a list of all current freedb servers...

    this is all really easy in telnet.

    can somebody help me do this in vb.net?
    or send me in the right direction?

    any help is ver much appreciated.
    thanks...
    Last edited by marvinklein; Aug 4th, 2004 at 06:01 PM.

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Do some research on using the System.Net.Sockets namespace to create connections via IP (Telnet is very similar). There are quite a few examples about, so have a look first before asking specific questions.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283

    Lightbulb

    Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click          
    Dim tcpClient As New System.Net.Sockets.TcpClient()   
    tcpClient.Connect("freedb.freedb.org", 8880)          
    Dim networkStream As System.Net.Sockets.NetworkStream = tcpClient.GetStream()          
    ' Read the NetworkStream into a byte buffer.          
    Dim bytes(tcpClient.ReceiveBufferSize) As Byte          
    networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))          
    ' Output the data received from the host to the console.  
    Dim returndata As String = System.Text.Encoding.ASCII.GetString(bytes)          
    MessageBox.Show(("Host returned: " + returndata))   
    If networkStream.CanWrite And networkStream.CanRead Then              
    ' Do a simple write.              
    Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes("cddb hello johndoe groton.org mediaplaya 1")              
    networkStream.Write(sendBytes, 0, sendBytes.Length)   
    ' Read the NetworkStream into a byte buffer.              
    ReDim bytes(tcpClient.ReceiveBufferSize)              
    networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))              
    ' Output the data received from the host to the console.  
    returndata = System.Text.Encoding.ASCII.GetString(bytes)              
    MessageBox.Show(("Host returned: " + returndata))     
    Else              
    MessageBox.Show("err")          
    End If      
    End Sub
    thats what i came up with...

    when i use telnet:

    i say: o freedb.freedb.org 8880 'the server returns a msg.
    i say: cddb hello johndoe groton.org mediaplaya 1 'the server accepts my login and responds with a msg..


    when i use my vb app, i get the first server response as a msgBox, but i don't get the second one...
    what is happening here????
    Last edited by marvinklein; Aug 4th, 2004 at 04:14 AM.

  4. #4

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283
    sorry about that code. how do i get the proper colorful formatting and line breaks???

  5. #5

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283
    ^bump
    it can't be that hard...

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Edit your posts and just press enter when you have a line end.

    Im very busy atm, so cant look into it, Ill check back later for you.

  7. #7
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    instead of 'code' '/code', use 'vbcode' '/vbcode' (brackets, not apostophes)

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Just had a couple of mins to look through, and its actually very easy and obvious when you look at it (took me 5 mins). When you connect via telnet, you type your message and press enter. Now you have to do exactly the same thing when going through your code (the same thing you needed to do on your post here as well!), just append a CRLF to the end like your pressing enter.

    VB Code:
    1. Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes("cddb hello johndoe groton.org mediaplaya 1" & vbCrLf)

  9. #9

    Thread Starter
    Registered User
    Join Date
    Jul 2001
    Posts
    283
    wow grimfort, i can't express my gratitude enough...
    is it usual that messages to a server need to be terminated like that? seems very logical now that i think about it, but i never would have thought of it.

    andy- thanks.. that should make my posts a bit clearer from now on...

  10. #10
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Yes, with data streams you just keep sending characters. The end connection doesnt know when you have finished typing. Using crlf informs it that you want it to act on everything you just sent to it.

    Have fun If you can rename your topic as RESOLVED it saves people trying to answer this .

  11. #11
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by marvinklein

    andy- thanks.. that should make my posts a bit clearer from now on...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width