Link to home
Start Free TrialLog in
Avatar of barkin
barkin

asked on

Winsock's Data Arrival Event Occuring Before Connect Event

Hi there,

I have been using the Winsock control for some time in my vb applications and have had no problems however just recently i have found that one of my winsock controls' events gets fired BEFORE it is supposed to.  More specifically, when i use the .Connect() function for this control it goes into a .State = 6 (Connecting) when this happens the control fires the event Data_Arrival() with 23 bytes (i believe) of data that has arrived DESPITE still being in "Connecting" state.  Shouldn't the control be in a "Connected" (state=7) state BEFORE windows auto triggers its Data_Arrival() event?  Anyway, when this "strange" data does arrive within this event procedure i use the .GetData() function and windows pops up an error indicating that the control is NOT in the correct state to receive this data yet (it is still in State = 6 mode -- Connecting).  

HOW THE HECK IS THIS POSSIBLE?  CAN SOMEONE TELL ME HOW IT IS DOING THIS AND HOW I CAN RESOLVE IT?

Btw, i have this control on a form and i make multiple instances of this form (i have done this with many other apps in the past with no problems but i just wanted to let you know).

READ THIS:

Hey, could it be that because i make a Connection to a remote site at a specific IP address (the port may change -- or it might be the same some times i guess) and then i shut down the connection via just hitting VB's STOP APP button or telling the remote side to cut the connection does some data linger in "limbo" so that when i restart the app and the connection is "reestablishing" (not quite yet fully connected) the remaining "Limbo" data is arriving now to me?


Thanks
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Please maintain your open questions:
Video Codec problems Date: 06/28/2002 11:50AM PST
https://www.experts-exchange.com/questions/20317476/Video-Codec-problems.html
MSDN .chm Help Integration Problems Date: 03/20/2002 09:32PM PST  
https://www.experts-exchange.com/questions/20279666/MSDN-chm-Help-Integration-Problems.html
SCSI Controller not working in DOS, why? Date: 06/27/2002 04:37AM PST  
https://www.experts-exchange.com/questions/20316853/SCSI-Controller-not-working-in-DOS-why.html
Any Wireless or PC service/software need improvement? Date: 07/08/2002 09:04PM PST  
https://www.experts-exchange.com/questions/20321076/Any-Wireless-or-PC-service-software-need-improvement.html
Cell-Phone/PDA Demographic.  Need help! Date: 07/13/2002 11:17PM PST  
https://www.experts-exchange.com/questions/20323096/Cell-Phone-PDA-Demographic-Need-help.html
Game Design or Programming Contest Exist? Date: 02/28/2002 07:19AM PST
https://www.experts-exchange.com/questions/20271895/Game-Design-or-Programming-Contest-Exist.html
Great Texture Image Repository - Where? Date: 06/10/2002 07:54PM PST  
https://www.experts-exchange.com/questions/20310095/Great-Texture-Image-Repository-Where.html
Commercial 3D Engines -- Whats the best? Date: 06/10/2002 07:43PM PST  
https://www.experts-exchange.com/questions/20310090/Commercial-3D-Engines-Whats-the-best.html
Great Texture Image Repository - Where? Date: 06/10/2002 07:58PM PST
https://www.experts-exchange.com/questions/20310099/Great-Texture-Image-Repository-Where.html
Merging AVI with WAV/MP3 sound -- How? Date: 02/23/2002 12:58PM PST
https://www.experts-exchange.com/questions/20270256/Merging-AVI-with-WAV-MP3-sound-How.html
Regular Exp & Matching Question Date: 04/28/2002 04:44AM PST
https://www.experts-exchange.com/questions/20294562/Regular-Exp-Matching-Question.html
Any Wireless or PC service/software need improvement? Date: 07/08/2002 09:02PM PST
https://www.experts-exchange.com/questions/20321075/Any-Wireless-or-PC-service-software-need-improvement.html
Kazaa Technology - How does it work? Date: 06/24/2002 12:28AM PST  
https://www.experts-exchange.com/questions/20315367/Kazaa-Technology-How-does-it-work.html
How do NEW Anti-spam methods work? Date: 06/25/2002 10:50PM PST
https://www.experts-exchange.com/questions/20316280/How-do-NEW-Anti-spam-methods-work.html
Email software apps - User Base and Who's Tops? Date: 06/25/2002 10:25PM PST
https://www.experts-exchange.com/questions/20316272/Email-software-apps-User-Base-and-Who's-Tops.html
Linksys WCF11 Wireless Broadband for PDAs ? Date: 06/25/2002 05:54PM PST  
https://www.experts-exchange.com/questions/20316220/Linksys-WCF11-Wireless-Broadband-for-PDAs.html

The following questions should be deleted as they have no contributions:
Why did GO's Pen device fail and PDAs succeeded? Date: 07/10/2002 06:00PM PST  
https://www.experts-exchange.com/questions/20321921/Why-did-GO's-Pen-device-fail-and-PDAs-succeeded.html
Netmotion Mobility sol'n for reliable mobile connection...How? Date: 07/05/2002 05:10AM PST  
https://www.experts-exchange.com/questions/20319892/Netmotion-Mobility-sol'n-for-reliable-mobile-connection-How.html
Adding DirectX Help Manuals into VC++ IDE.  How? Date: 03/12/2002 07:17AM PST
https://www.experts-exchange.com/questions/20275881/Adding-DirectX-Help-Manuals-into-VC-IDE-How.html

Thanks,
Anthony
There is a soulution for this problem. You get this problem a lot when you are spamming....I look forward to providing the solution.
Avatar of anu1401
anu1401

try this way out!!!

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
If lblAttach.Caption <> "" Then
    Inet1.Execute tcpServer.RemoteHost, "GET " & lblAttach.Caption & " /" & lblAttach.Caption
        StatusBar1.Panels(2).Text = "File Received"
    FileName.CopyFile , "", "C:\Windows\Desktop\*.*"
    lblAttach.Caption = CommonDialog1.FileName
    StatusBar1.Panels(2).Text = "File Saved"
Else
    Dim StrData As String
    tcpServer.GetData StrData
    txtOutputData.ForeColor = vbBlue
    txtOutputData.Text = txtOutputData.Text & "Client : " & StrData & vbCrLf
End If
    If frmServer.WindowState = vbMinimized Then
        frmServer.WindowState = vbNormal
    End If
    lblAttach.Caption = CommonDialog1.FileName
    StatusBar1.Panels(2).Text = "File Received"
    StatusBar1.Panels(2).Text = ""
End Sub
Avatar of barkin

ASKER

It turns out after playing with this control that it has to do with a BUG in Winsock revolving around Asynchrony...If you receive data while connecting this data arrives prior to the .State changing to 7 (Connected),.  It is a known bug in the control.
So, how do i delete/close this message on my own Answer?
Post a message in Community Support (https://www.experts-exchange.com/commspt/)

The same goes for these messages:
MSDN .chm Help Integration Problems Date: 03/20/2002 09:32PM PST
https://www.experts-exchange.com/questions/20279666/MSDN-chm-Help-Integration-Problems.html
Why did GO's Pen device fail and PDAs succeeded? Date: 07/10/2002 06:00PM PST
https://www.experts-exchange.com/questions/20321921/Why-did-GO's-Pen-device-fail-and-PDAs-succeeded.html
Netmotion Mobility sol'n for reliable mobile connection...How? Date: 07/05/2002 05:10AM PST
https://www.experts-exchange.com/questions/20319892/Netmotion-Mobility-sol'n-for-reliable-mobile-connection-How.html
Cell-Phone/PDA Demographic.  Need help! Date: 07/13/2002 11:17PM PST
https://www.experts-exchange.com/questions/20323096/Cell-Phone-PDA-Demographic-Need-help.html
Adding DirectX Help Manuals into VC++ IDE.  How? Date: 03/12/2002 07:17AM PST
https://www.experts-exchange.com/questions/20275881/Adding-DirectX-Help-Manuals-into-VC-IDE-How.html

Thanks,
Anthony
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial