Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem
Winsock DataArrival event timing problem Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Go Back  Xtreme Visual Basic Talk > > > Winsock DataArrival event timing problem


Reply
 
Thread Tools Display Modes
  #1  
Old 11-04-2010, 01:32 PM
wayneh wayneh is offline
Centurion
 
Join Date: Mar 2004
Posts: 123
Exclamation Winsock DataArrival event timing problem


(VB6)

I'm having a timing issue with Winsock (perhaps it's an understanding issue too).

I have a TCP chat program, and I'm trying to account for a 'broken connection' with Winsock. For example, if a PeerA suddenly quits (crash, machine shut down, etc), then PeerB doesn't know the connection is lost.
Winsock.State does not accuratley reflect this - it still thinks sckOpen or sckConnected is true. Of course Winsock.Send does not throw an error if the connection is gone!

So the only way to verify the connection between PeerB and PeerA is to 'ping'
PeerA prior to trying to chat with it.

This is the problem:
I'd like to ping PeerA and see if there is a response prior to each attempt to Send.
When I have a Sub that executes the Winsock "Send" method, the Winsock "DataArrival" event doesn't fire until the Sub is ended, and no other routine is running.

The problem is that I'd like the return data value while still in the original Sub.

For example (pseudo code):

Code:
Sub SendIt()
   Winsock1.Send "Hello"
   If returnVal=True then
      ...more code...
   else
      ...even more code....
   end if
End Sub

Sub Winsock_DataArrival(...)
    ...process data....
    If data=x then
       returnVal=True
    else
       returnVal=False
    end if
End Sub
Is there a way to execute a "Send" and get the resulting "Arrival"
without sitting in some kind of horrible loop?
Reply With Quote
  #2  
Old 11-04-2010, 03:27 PM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default Ping-Pong

Maybe I don't understand your question completely but here's what I'll say:

Ping-Pong is the right idea. Just don't use a timer with like less than 1000ms. I think that is what I would stick with. Save on the bandwidth when possible and this is just one way you could.

What is this loop your worried about? The ping and pong back and forth? That doesn't take very much.

If you mean, can you send data and know the client received it, well no, not without a reply back from the client. That is why you play the ping-pong game LOL.

Hope I helped in this case.
__________________
ZaCkO ... Who is your attitude?
Reply With Quote
  #3  
Old 11-04-2010, 03:34 PM
wayneh wayneh is offline
Centurion
 
Join Date: Mar 2004
Posts: 123
Default

Well, the problem is really that the DataArrival event won't fire until I'm out of the Sub that originally used the .Send method.
Reply With Quote
  #4  
Old 11-04-2010, 06:40 PM
ZaCkOX's Avatar
ZaCkOX ZaCkOX is offline
Contributor
 
Join Date: May 2006
Location: CA
Posts: 645
Default Hmm

You shouldn't have a problem, but I still don't see how you have one.

Ping Pong, you would have the server with a timer, the timer sends a data string every 1 second or longer to a client. Once the client gets the string, it immediately sends back data. You have a different timer to make sure the pong came back in time.

If you have a problem where Windows needs to breathe or sometimes the .send data is not going off properly, you can try

Code:
DoEvents

After ,send data, but don't use it unless you have too. Sometimes it can help and sometimes it can be worse off for you. Just depends on your situtation.
__________________
ZaCkO ... Who is your attitude?
Reply With Quote
  #5  
Old 11-09-2010, 08:04 AM
Banjo's Avatar
BanjoWinsock DataArrival event timing problem Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Default

Indeed. Doevents is the problem here. Here's roughly what you need:

Code:
SendPing
startTime = Now
Do Until bPingResponded = True Or startTime + X > Now
    Doevents
Loop
If bPingResponded Then
    SendMessage
Else
    Msgbox "ERROR"
End If
The bPingResponded is set in the DataArrival event.
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #6  
Old 11-11-2010, 09:08 AM
wayneh wayneh is offline
Centurion
 
Join Date: Mar 2004
Posts: 123
Default

OK - thanks for the input - I'll look into it.

On my other related thread I posted that I'm also going to try changing from UDP to TCP and re-work some of the code. It seems that may be the best way anyway....
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
 
Winsock DataArrival event timing problem
Winsock DataArrival event timing problem
 
-->