11-20-2000, 07:01 AM
I'm using the winsock control in VB5 to create a Tcp client/server program for sending and recieving data. The problem is, I can't seems to close a connection properly, even if use the .close method. Everytime time I try to reconnect, I get 'Address in Use'. The only way I can get around it is to change the port number of both client and server programs, which is not really feasible at run time. Can anyone tell me what I'm doing wrong, or what I'm not doing that I should do.
11-20-2000, 12:00 PM
Are you writing both the client and the server? If so, are you closing on both ends? I'm not sure, but it sounds like one of the sides are left hanging upon close.
11-21-2000, 05:10 AM
Yeah you were right, I forgot to close one of them. D'oh!!!
I've got another problem though:
I'm sending data from a recordset created on the server side, one field at a time using the prefix DT to determine that the item being sent is data, and putting the data into a listbox on my client machine. The problem is, that as I loop though the fields collection of my recordset, the send the data using <font color=green>winsock.senddata</font color=green>, it seems to group all the data together and send it in one big chunk so it looks like this:
<font color=blue>DTMattDTRobertDTNash etc....</font color=blue>
When I step through the program using f8, I get
Which is actually what I want.
I've tried sticking a vbCrLf at the end but it still doesn't work. Any ideas people? All, help will be much appreciated.
11-21-2000, 10:28 AM
Hmmm. Are you grouping the data like this?
string1 = "DTMatt" + vbCrLf
String1 = "DTRobert" + vbCrLf
Or like this...
String1 = "DTMatt" + vbCrLf
String2 = "DTRobert" + vbCrLf
Winsock should be preserving the carriage returns and/or line feeds.
In any case, a better way might be to set up modes of operation. For example. Let say you want to send data. You could do it like this
This would trigger the reading program to put everything into data (that is until you turn that mode off by setting another mode). Change your modes by putting two dashes (or any other combination of characters you feel would be unlikely to occur in your data) in the data stream. Depending on what mode you are in, your program will react differently.
Check out the SMTP Email program in the examples on this site. It has a good example of using the winsock to communicate with an SMTP Server. That should give you a working example of the methodology I just described.
Hope this helps
11-22-2000, 03:44 AM
Thanks a lot for your help.