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.
1 Attachment(s)
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.
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?
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.
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).
1 Attachment(s)
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.
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".
1 Attachment(s)
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.
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?
Re: need help with TCP client
You can use the Split() function.
ie:
VB Code:
Dim strInfo() As String
'The weather data is seperated (delimited) by a space character.
'Split each item into an array.
strInfo() = Split(strWeatherData, " ")
'Then some code to see the array.
Dim intLoop As Integer
'Loop through the strInfo() array.
For intLoop = 0 To Ubound(strInfo())
Debug.Print "strInfo(" & intLoop & "): " & strInfo(intLoop)
Next intLoop
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?
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:
Dim intTemp as integer
intTemp = CInt(strInfo(0))
'etc...
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?