Results 1 to 13 of 13

Thread: need help with TCP client

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    need help with TCP client

    I am trying to write a cimple TCP client in VB6. I can connect to the server and read the first line (the greeting). After that, I try to send my computer information to the server ("user@host" for now). I dont know if i need to send a return character for my GetData to read the next line or not. Here is my code:

    Dim server_greeting As String
    Dim ACK As String

    Private Sub Form_Load()
    'Closes any possible open connection
    Sock.Close
    'Connects with the server
    Sock.Connect
    'Message box telling you are connected
    MsgBox "Connected"
    'Reads the greeting
    Sock.GetData server_greeting
    'Message box displays the greeting
    MsgBox server_greeting
    'Sends user@host
    Sock.SendData "user@host"
    'Reads the ACK
    Sock.GetData ACK
    'Displays ACK message
    MsgBox ACK
    'Closes connection
    Sock.Close
    End Sub


    I have the server and port information already entered in the winsock's properties so I dont need to put it into code. Any help will be greatly appreciated. The server is ryker.aet.cup.edu, the port is 44001.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    You're still not using the Winsock control properly. Did you read the post in your other thread?

    Anyway, here you go, this works.
    Attached Files Attached Files

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    Another problem I was having was after i send the "user@host" to the server. After that message is sent, another acknowledgment is supposed to be sent. Then after that ACK, we are supposed to send the letter "c" that will then spew out a long line of data. Any ideas on how to do that?

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    Seems like that server wants you to send a vbCrLf after everything you send it, so try that. If that doesn't work, try vbCrLf & vbCrLf

    You will need to find out the protocol it uses so you can make your client program communicate with it. You would have to contact the developer of the server to find that out.

    If there is another client program already made, you can use a port monitor/packet sniffer to watch what data is being sent/received from client to server and learn the protocol that way.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    We are using our own protocol. Basically, we connect to the server, the server sends the greeting and waits for the client to send the user@host. The server then sends back an ACK. Then the server waits for a command (sending the character "c" sends back current weather data).

  6. #6
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    Quote Originally Posted by stx531
    We are using our own protocol. Basically, we connect to the server, the server sends the greeting and waits for the client to send the user@host. The server then sends back an ACK. Then the server waits for a command (sending the character "c" sends back current weather data).
    Well, I tried again and following the steps you described, this is the data I got back, not sure if this is the weather data or not.

    Code:
    19:25 732 408 11 246 29162 34 60 7638 1366 714 408 278 281 413 120 29144 571
    I attached the project.
    Attached Files Attached Files

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    Yep that is it. In your code, where is the weather data being stored? Also when I run, it says "Unknown Data Recieved".

  8. #8
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    I updated the code so the weather data gets stored into a variable, and also fixed the other few things such as it saying "unknown data received".

    The protocol isn't setup that well, but if this is the only data you'll be sending to client/server it should be okay.

    Here's the project.
    Attached Files Attached Files

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    Now that I have the data, how can I break it up into different variables? Some kind of loop I assume?

  10. #10
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    You can use the Split() function.

    ie:

    VB Code:
    1. Dim strInfo() As String
    2.  
    3. 'The weather data is seperated (delimited) by a space character.
    4. 'Split each item into an array.
    5. strInfo() = Split(strWeatherData, " ")
    6.  
    7. 'Then some code to see the array.
    8. Dim intLoop As Integer
    9.  
    10. 'Loop through the strInfo() array.
    11. For intLoop = 0 To Ubound(strInfo())
    12.     Debug.Print "strInfo(" & intLoop & "): " & strInfo(intLoop)
    13. Next intLoop

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    Is the split function only usable for strings? How can I change the weather data to integers so that I can do calculations?

  12. #12
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: need help with TCP client

    Quote Originally Posted by stx531
    Is the split function only usable for strings? How can I change the weather data to integers so that I can do calculations?
    You can convert the strings to integer or whatever other data type you need, so you can do calculations.

    ie:

    VB Code:
    1. Dim intTemp as integer
    2.  
    3. intTemp = CInt(strInfo(0))
    4. 'etc...

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    12

    Re: need help with TCP client

    When I tried to convert the variable to an integer, it gives me an error saying "Subscript out of range". Is that the right way to change each part of an array?
    Last edited by stx531; Dec 4th, 2006 at 09:40 PM.

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