?
Solved

WinSocket data arrival event hangs

Posted on 2001-08-28
18
Medium Priority
?
625 Views
Last Modified: 2013-11-13
I have a problem in one of the projects i am working at, we are using winsocket control to establish a connection , send data... then waiting for a response from other server...
the problem we are facing is happening during the data arrival from the other server, inside the winsocket DataArrival event when we are trying to call  winsocket.GetData method to collect responses...
it seems that it hang and stay there...
i figured that out by writing a someting to a log file before and after the call to  winsocket.GetData inside DataArrival event...

one last notes:
(1) this problem doesn't happens all the time.
(2) This behavior doesn't fire the winsocket error event.
Please provide me with help?
0
Comment
Question by:Suzan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6435501
I noted that the winsocket is not really good to be debugged... the events are not raised the same way in the IDE than when compiled...
0
 

Expert Comment

by:Arvindtn
ID: 6435540
what is the amount of data you try to send?
Also what is the frequency of Send method call?
0
 

Expert Comment

by:Arvindtn
ID: 6435543
can u show the code where u send the data and the Data Arrival event code...

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:Suzan
ID: 6435580
The problem isn't in the data i sent..... it's during receiving the data
The DataArrival event code is
   
    If objWinsock.State = 7 Then
      objWinsock.GetData strData
   
    strRecievedData = strRecievedData & strData

the amount expected to be recieved about 1k - 25 K or more i am not really sure since this is out of my scope
0
 

Expert Comment

by:Arvindtn
ID: 6435624
I think this would solve ur problem

sckReceiver is a Socket Control Array

Private Sub sckReceiver_DataArrival(Index As Integer, ByVal bytesTotal As Long)

   Dim v_MessageReceived As String
   Dim v_MessageInPartsReceived As String
   v_MessageReceived = ""
   Do While Len(v_MessageReceived) < bytesTotal
      sckReceiver(Index).GetData v_MessageInPartsReceived
      v_MessageReceived = v_MessageReceived & v_MessageInPartsReceived
   Loop
   ' ProcessMsg is a method which process the message
   ProcessMsg v_MessageReceived
   ' This call makes the other messages received to be put in a queue and it is processed based on FIFO
   DoEvents
End Sub

First try it in ur DataArrival event, still if u have problem try placing the DoEvents as the first line in your DataArrival event

even if this does not work, If the Server is sending the data in a Loop, then u have add the DoEvent keyword in the place where u are sending the data.


Hope this solves ur problem

Arvind
0
 

Author Comment

by:Suzan
ID: 6435819
I think i didn't gave an  accurate idea about what happening whith me here,so This is the whole algorithm , i am using to connect/send data and receive data from TEST server

The hanging happens at the following line:
wsktest.GetData strTempData
I know that because when tha hang happenes , i looked  at log file and found the "Data Arravial: begin" written  without "Data Arravial: End"

I don't really know why wsktest.GetData  hanged since the dataArrival events not fired unless there is data that is waiting to be collected, so why is the hang? and how to forbid it?



Public strRecievedData As String

Private Sub wsktest_DataArrival(ByVal bytesTotal As Long)
Dim strTempData     As String

      AddToLog "  Data Arravial: begin"
      wsktest.GetData strTempData ' The application hang here
      strRecievedData = strRecievedData & strTempData
      AddToLog "  Data Arravial: End"
   
End Sub

Public Function SendthroughSockets() As Variant

    Dim flgTimeOut As Boolean
    Dim dtConnectionStart  As Date
    Dim strXMLDateSent  As String
    Dim intsocketResTimeOut As Integer
   
    flgTimeOut = False
    dtConnectionStart = Now
    intsocketResTimeOut = 180 ' time out time in seconds

    With frmMain
        .wsktest.RemoteHost = "" ' TEST IP
        .wsktest.RemotePort = "" ' TEST Port
        .wsktest.Connect
       
        .wsktest.Tag = False ' Tag used to detect if there is Error Rasied to the Socket
       
         'Wait till connection is established
         While .wsktest.State <> 7 And .wsktest.Tag = False And Not flgTimeOut
            DoEvents
            If DateDiff("S", dtConnectionStart, Now) >= intsocketResTimeOut Then
                flgTimeOut = True
            End If
        Wend
       
        'No timeout and no sockets error while establishing connection
        If .wsktest.Tag = False And Not flgTimeOut Then
               ' Send the XML data to Test via sockets
               .wsktest.SendData strXMLDateSent
               
               flgTimeOut = False
               dtConnectionStart = Now
               .wsktest.Tag = False ' Tag used to detect if there is Error Rasied to the Socket
               
               
               ' wait untill Response recieved from Test
               '"EORTest" is tag the show that all the data have been received( it came as part of received data)
               Do While .wsktest.Tag = False And InStr(1, .strRecievedData, "EORTest") = 0 And Not flgTimeOut
                   DoEvents
                   If DateDiff("S", dtConnectionStart, Now) >= intsocketResTimeOut Then
                       flgTimeOut = True
                   End If
                   DoEvents
                   DoEvents
               Loop
               
               'No timeout and no sockets error while waiting response
               If Not flgTimeOut And .wsktest.Tag = False Then
                     SendthroughSockets = .strRecievedData
               End If
        End If
    End With

End Function


0
 
LVL 5

Expert Comment

by:Julian_K
ID: 6436244
1. Which protocol are you working with? TCP or UDP?
2. I remember there were some problems with winsock control, that were fixed in Service Pack #5. Have you installed it?
0
 

Author Comment

by:Suzan
ID: 6436427
1. I am using TCP protocol.
2. I didn't install it.......
are you talking abut the fix of the following problem:
"Repeatedly loading and unloading a WinSock control causes a memory leak."

and do you think this is what happenes?  please advise.

0
 

Expert Comment

by:Arvindtn
ID: 6436468
 I had faced the same problem earlier and i gave the DoEvents in the DataArrival event for it to work.

  Have you tried using the DoEvent in the Dataarrival event which i had posted earlier.

  Can u also write the Number of Bytes received (bytesTotal) before calling GetData.

 

0
 

Author Comment

by:Suzan
ID: 6436486
1. I am using TCP protocol.
2. I didn't install it.......
are you talking abut the fix of the following problem:
"Repeatedly loading and unloading a WinSock control causes a memory leak."

and do you think this is what happenes?  please advise.

0
 

Author Comment

by:Suzan
ID: 6436508
the problem, that i could not duplicate the problem ......
it happenes only at client side........
so, i try to guess a solution....
I will try DoEvents and wait ......
if the client have no more complains...... then the problem is solved.

thank you a lot  for your help.
0
 

Author Comment

by:Suzan
ID: 6436537
the problem, that i could not duplicate the problem ......
it happenes only at client side........
so, i try to guess a solution....
I will try DoEvents and wait ......
if the client have no more complains...... then the problem is solved.

thank you a lot  for your help.
0
 

Expert Comment

by:Arvindtn
ID: 6436616
you are welcome.
0
 

Author Comment

by:Suzan
ID: 6436629
the problem, that i could not duplicate the problem ......
it happenes only at client side........
so, i try to guess a solution....
I will try DoEvents and wait ......
if the client have no more complains...... then the problem is solved.

thank you a lot  for your help.
0
 
LVL 1

Accepted Solution

by:
LuckyPhill earned 1000 total points
ID: 6439111
More ideas that may help...

be careful here, Doevents can be a problem in an event handler resulting in a stack overflow if your server is stressed. (ie lots of connections) ....

Keep your send size to under 8k, 8k is the default socket send buffer size under NT, 95 & 98, send any more and the socket layer will break it up into multiple sends...

If your problem persists run a full Stack trace on the module.. This diagnostic method has solved many socket related problems for me, just like the one you are encountering....



Stack trace example:

sub firstSub()
  call StackTrace("firstSub")
...
  call StackTrace("")
end sub

sub secondSub()
  call StackTrace("secondSub")
...
  call StackTrace("")
end sub

sub StackTrace(msg as string)
 static level as integer
 dim fp as integer

 if msg="" then
   level=level-1
   exit sub
 else
   level=level+1
 endif

 fp=freefile
 open "c:\stack.log" for append as fp
 print #fp, space(level) & msg
 close fp
end sub



0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7205251
Hi Suzan,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept 's comment(s) as an answer.

Suzan, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7707883
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to LuckyPhil
Please leave any comments here within the
next seven days.
0
 

Expert Comment

by:modulo
ID: 7758366
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question