Suzan
asked on
WinSocket data arrival event hangs
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?
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?
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...
what is the amount of data you try to send?
Also what is the frequency of Send method call?
Also what is the frequency of Send method call?
can u show the code where u send the data and the Data Arrival event code...
ASKER
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
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
I think this would solve ur problem
sckReceiver is a Socket Control Array
Private Sub sckReceiver_DataArrival(In dex 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
sckReceiver is a Socket Control Array
Private Sub sckReceiver_DataArrival(In
Dim v_MessageReceived As String
Dim v_MessageInPartsReceived As String
v_MessageReceived = ""
Do While Len(v_MessageReceived) < bytesTotal
sckReceiver(Index).GetData
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
ASKER
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
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
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?
2. I remember there were some problems with winsock control, that were fixed in Service Pack #5. Have you installed it?
ASKER
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.
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.
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.
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.
ASKER
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.
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.
ASKER
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.
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.
ASKER
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.
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.
you are welcome.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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.
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.
Finalized as proposed
modulo
Community Support Moderator
Experts Exchange
modulo
Community Support Moderator
Experts Exchange