Google Answers Logo
View Question
 
Q: Visual Basic Winsock Programming Question ( No Answer,   3 Comments )
Question  
Subject: Visual Basic Winsock Programming Question
Category: Computers
Asked by: plop-ga
List Price: $10.00
Posted: 11 Mar 2003 02:20 PST
Expires: 10 Apr 2003 03:20 PDT
Question ID: 174560
Visual Basic Winsock Programming Question. 

I have a VB socket server written using
Microsoft's Winsock Control shipped with Visual Basic 6.0(MSWINSCK.OCX
- Version 6.0.81.69) and talking to a 3rd party socket client written
in Visual C++. I have access to the server source code but not the
client.

What happens is this: Numerous messages are exchanged every second
between client and server and once in a while, 2 messages are received
together (merged into each other) on the client. the merging happens
intermittently but especially when more than one message is sent at
the same time to the client. This causes the client to stuff up.

I heard that simply calling a DoEvents after tcpServer.SendData should
resolve this, but it has not. I have tried calling DoEvents in a long
For Loop, which works ... but this approach works only for very large
counter values (e.g. Loop half a million times) and produces an
unacceptable delay in transmission of all messages.
e.g. 
For i=1 To 500000
  DoEvents
Next i

Looking URGENTLY for advice to solve this. Theory on Sliding Windows
and Nagle's algorithm etc. is welcome but what I am really looking
for, is a concrete, simple and practically achievable solution.

Secondary Question:

1. The socket client is owned by another vendor. Can they do anything
to fix this?

Clarification of Question by plop-ga on 11 Mar 2003 02:41 PST
Introducing program-level delays (e.g. 'Sleep') between messages is
unacceptable. I am unable to change the fact that the server will send
multiple messages to the client at the same time. This is because they
are in turn triggered by asynchronous events, which may fire at the
same time.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Visual Basic Winsock Programming Question
From: maxhodges-ga on 11 Mar 2003 03:16 PST
 
of course contact your vendor. maybe this is a known issue.
Subject: Re: Visual Basic Winsock Programming Question
From: br-ga on 11 Mar 2003 07:13 PST
 
There is an easy solution

The messages are probably sent together with a vbCrLf after the first
Chr(13) and Chr(10) -- which is basically the windows return
character.  Extract the messages, using Mid, Left, and Right depending
on how many messages are in one stream.  Shouldn't be too hard to code
once you figure out the character(s) which are separating the
messages!

Good luck!
Subject: Re: Visual Basic Winsock Programming Question
From: jeremyhuffman-ga on 15 Mar 2003 17:51 PST
 
When the server sends multiple messages to the single client at the
same time, is it sending them using the same instance of the socket?
If so, then there is probably not a way for the client to distinguish
between the two separate processes. What you need to do is synchronize
responses for each client - that is make it so that only one message
is sent to each client at a time, while continuing to asynchronously
serve your other clients. This is possible without impacting
performance.

Visual Basic 6 doesn't directly support synchronizing code - for
instance it does not offer a synchronize keyword like Java does. What
you can do is use the Win32 mutex API to perform the synchronization
yourself. Basically you name your mutex something meaningful for that
client connection (maybe the port you speak to it on) - if you
successfully lock the mutex then you proceed onwards with your message
- otherwise you loop, sleep and try to lock the mutex until you
succeed. This is the basic technique for resolving all synchronizing
issues in all programming languages, but some languages make it easier
than others. The basic API you will use is CreateMutex - I even found
a google groups thread where its usage is discussed with a practical
example.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=1856c01c29590%247b333d20%248df82ecf%40TK2MSFTNGXA02&rnum=2&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dvb%2Bmutex

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy