PDA

Click to See Complete Forum and Search --> : [RESOLVED] winsock not sending all data


mojo69
Aug 10th, 2007, 10:52 AM
Problem:
Using winsock to send a string to a server machine. The software on the server looks at the string and the length. If the length is not correct then we get error generated "incomplete message detected". Now 99.95 % of the time this process is fine and no error generated. the other .05% of the time or so the length is not equal. I am using tcp/ip and not udp from a visual basic 6.0 program.

Question:
Is winsock cutting off or losing some of the data somewhere?

DigiRev
Aug 10th, 2007, 12:10 PM
No.

What is your code for sending the data? And more importantly, what is your code for the receiving end?

mojo69
Aug 10th, 2007, 02:31 PM
We have a client/server project written in Visual Basic 6.0. It is using the MS Internet Transfer Control to send a sql string from the client to the server. In turn the server processes the sql statement and sends the results back to the client. With the requests/results we tag on the length of the data sent. We are getting an 086 incomplete message from our program. This is generated by the program when it runs into a wrong protocol or connection state for the requested transaction or request or a 40006. I inherited this project and the previous programmer has some comments about the 40006 being handled due to a windows access violation and the winsock buffer needing to be cleared. What he was doing for us was using a faster concatenation routine for assembling the data to send back. We looked at the kb article 183987 dated october 28,2003 and kb article 319692 dated october 5, 2005. What do we need to do to prevent this from happening. It says there is a hotfix but I am not sure that I want to download without knowing what that will do first. Both the server and client use the .ocx control that contains the MS Internet Transfer Control.

When the client is sending the data it uses len(strSent) and puts that in strSent. When the server has received the data it grab the length out of the string and then uses len(strReceived). If they do not match then it throws the error. It seems maybe the winsock is being closed to soon??

DigiRev
Aug 10th, 2007, 02:41 PM
Are you using the Winsock control or the Microsoft Internet Transfer Control (Inet)? They're 2 different controls but both use the underlying Winsock API functions.

If you're using the Inet control (MSINET.OCX) instead of the Winsock control (MSWINSCK.OCX) then I'm not sure. It would help to see what code you have, otherwise it's just guesswork.

My guess is you're using the Inet control on the client and the Winsock control on the server?

Your guess about the Winsock being closed to soon is definitely a possibility and would be my first guess.

Remove any Winsock.Close() statements from the server just to see if that works. If that fixes the problem, then post your code and I can tell you where to put it.

If that's not the problem, then it could be the receiving end. All of the data will probably not arrive at once, and will probably be split up into separate pieces by TCP (you don't have any control over this).

So, it is important to buffer the data as it comes in. You will need a public-scope variable to store it in. In the general declarations of the form, or in a module somewhere. And every time data arrives, add it to the buffer variable. And each time, check if all of the data has been received. If it has, then process the data in the buffer.