Data sending Winsock problem?
Hi guys,
I developed a tool that sends data to a remote server... like this :
If txt1.State = sckConnected Then
txt1.SendData InputDataW
txt1.Text = ""
List1.Clear
Else
MsgBox "Not connected"
End If
Now the thing is that 1 in 10 or sometimes 4-10 data sendings i get a partial string on the server instead of an entire string i sent...
What could cause that?:confused:
Re: Data sending Winsock problem?
Duh....are you sure txt1 is Winsock? Funny name for a Winnsock control.
Oh, well, you need to close the socket on the client side after you send the data so the recieving end (the server) can get all of the data and in it's Socket_Close event is where you capture all of the sent data. Also you need to buffer the data in the DataArrival event.
Server....
Code:
'
'
Dim InputBuffer As String
'
'
Private Sub Socket_DataArrival(.....)
Dim s as String
Socket.GetData s
InputBuffer = InputBuffer & s
End Sub
Private Sub Socket_Close()
Socket.Close
Text1.Text = InputBuffer
End Sub
Re: Data sending Winsock problem?
well yeah i wrote it wrong for the winsock :D
this is what i got :D
on click:
wPostW.Close
wPostW.Connect "www.sitename.org", 80
winsock connects:
If wPostW.State = sckConnected Then
wPostW.SendData InputDataW
txtPostW.Text = ""
List1W.Clear
Else
MsgBox "Nisi spojen"
End If
data arrival :
Private Sub wPostW_DataArrival(ByVal bytesTotal As Long)
Dim strResponse As String
wPostW.GetData strResponse, vbString, bytesTotal
txtPostW.Text = txtPostW.Text & strResponse
wPostW.Close
Re: Data sending Winsock problem?
No. Do not close the socket in the DataArrival event. Do what I posted before.
BTW:
The client sends the data so it will not have a DataArrival event. The server gets the data so it will.
Unless, of course, the server sends something back to the client. But still, never close sockets in the DataArrival events. Do it the correct way and close them in the _Close events.
Here's how it works.
One application, usually the client, will ask the server for some data. OK, so the client sends a request to the server. The server gets the request and sends the data to the client. When the server sends the data to the client he closes his socket after his _SendComplete event is fired. The client on the otherhand will get his _Close event fired and here the client closes his socket.
Re: Data sending Winsock problem?
M8 ill try this tomorrow im gogin to sleep now
tnx ill try that tomorrow and i got a feeling it will work...
Thank you for your time and reply...
Ill post tomorrow....
Thanks again and good night :D
Re: Data sending Winsock problem?
K m8 i did that:
Private Sub Socket_Close()
Socket.Close
Text1.Text = InputBuffer
End Sub
Text1.Text = InputBuffer
why do i need that in the close socket porcedure?
i will tetst the app now because i have to test it a few minutes to see if that error happends again..
Re: Data sending Winsock problem?
Quote:
InputBuffer = InputBuffer & s
Because you just raise the buffer in the Socket_DataArrival event, but didnt displayed it. But it will be displayed when the socket closing, that means everything is just came thru the socket.
But, you have been changed the dataarrival, that @jmsrickland show you, but you forgot to clean up the text1.text = inputbuffer. You dont need it anymore, since you directly write to the textbox object (txtpostw)
Quote:
txtPostW.Text = txtPostW.Text & strResponse
Re: Data sending Winsock problem?
So actually i can put the inputbuffer data to show up in textbox in data arrival or is still better to put it in the closing procedure?
Well i'm not that worryed about that data arrival because i get encocded data and i cant decoded...
But acutally i did remove the .close function from DATA_ARRIVAL and the error went down alot...but still i get it sometimes...
COuld it be because i didnt add and doevents or something at the winsock.senddata procedure???
it seems that things are even worse when aading doevents
Re: Data sending Winsock problem?
You can send as much data as you just want, the packets will be queued. theres you dont have to use a doevents. however, the packets are not sent by in whole big package, but in smaller partials, around 1-2 kbyte at a time. The 'sender' is sends a packet, that the receiver accepts, and will send an 'ack' that the sender know the packet has been arrived, it can send the next one.
The partial string problem is can occurs, because you may having some network issues, just like lagging, the packet receiver may give up to waiting a packet to be completed, it just give the part that is received successfully before.
It may be even better to see both the server/client side of your program, to know what else can lead to this error.
Re: Data sending Winsock problem?
Hmmm....yeah...i was thinking about that too....i think i got some packet loss :S
Well guys...thanks for your support i did like you told me to do...it seems ok now, better then before.
Re: Data sending Winsock problem?
Btw guys...
I wanted to ask something.
I've noticed now that when i download alot...intensively i get more errors...could i in some way make winsock priority MAX or maybe to put MAX priority in Processes (task manager)
What do you think, would that work?
Re: Data sending Winsock problem?
Quote:
intensively i get more errors
Winsock is not that sensitive, not like it works on you atm. I have a feeling you have done some accidentaly mistake in your code, that leads to these errors. You can't Prioritize your application on network usage. The main problem is may because you download using some P2P application, those generate a brutally huge amount of packet trafic. Well, this can lead to some packet loss, because of its design, however there is a packet sorting/handling service is running on your pc, that should handle the packets in the right, well organized way.
You shouldn't have to get any issues.
Post your whole code here, both server/client side in a ZIP package to see what is it does.
Re: Data sending Winsock problem?
Sure m8 i will...
let me pack it all
edit:
well m8 i dont have the server side...i made just the client side...i post data to a http server...
well ill pack it for yoou anyway
edit:
i think the error is becauase of the laggy server not because of the app....i'll still make some test with packet capture softwares to check it.
Re: Data sending Winsock problem?
You have a problem in your code....
Code:
Private Sub wLoginW_DataArrival(ByVal bytesTotal As Long)
Dim strResponse As String
Dim LoggedFound As String
wLoginW.GetData strResponse, vbString, bytesTotal
strResponse = FormatLineEndings(strResponse)
' MsgBox strResponse
' we append this to the response box becuase data arrives
' in multiple packets
txtLoginWW.Text = txtLoginWW.Text & strResponse
Dim ArrLines() As String
Dim i As Integer
Dim Lines As Long
Lines = SendMessageAsLong(txtLoginWW.hwnd, EM_GETLINECOUNT, 0, 0)
On Error Resume Next
For i = 0 To Lines
ArrLines = Split(txtLoginWW.Text, vbCrLf)
List1WW.AddItem ArrLines(i)
Next i
txtUcookieWW.Text = Mid(List1WW.List(6), 13, 122) ' & Mid(list1W.List(10), 13, 48)
txtUsidWW.Text = Mid(List1WW.List(7), 13, 47)
If txtUsidWW = "" Then
lbloggedWW.Caption = " Check your username and password "
lbloggedWW.BackColor = vbRed
Else
lbloggedWW.Caption = " You have successfully logged in "
lbloggedWW.BackColor = vbGreen
End If
End Sub
You get a Subscript Out Of Range error on the List1WW.AddItem ArrLines(i).
Do you see why?
Re: Data sending Winsock problem?
Well m8...yeah i maybe getting the error there...but i do the login once...and later on i dont login anymore i maintein the session...the problem is with
wPostw
I always login with wloginW with no problems.
The issue is the wpostW function :( that in 80% of the cases sends whole data set...and in 20% does not... hmmm strange...
Could it be because of the server?
Re: Data sending Winsock problem?
Well m8...yeah i maybe getting the error there...but i do the login once...and later on i dont login anymore i maintein the session...the problem is with
wPostw
I always login with wloginW with no problems.
OK, it's your code and you know best.
The issue is the wpostW function that in 80% of the cases sends whole data set...and in 20% does not... hmmm strange...
Could it be because of the server?
Either that or your FormatLineEndings is not working right.
Re: Data sending Winsock problem?
M8 thanks for replying...
i did change the .close function as you told me..
Thank you for that.
Ill try to fix the problem..when i do i'l let you know :D
Re: Data sending Winsock problem?
BTW:
Add _Error events for your two sockets. That way you might be able to catch any socket errors that may occur that could cause your lose of data.
Code:
Private Sub wLoginW_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error has occured on wLoginW: " & vbCrLf & vbCrLf & Description
End Sub
Private Sub wPostW_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error has occured on wPostW: " & vbCrLf & vbCrLf & Description
End Sub
Re: Data sending Winsock problem?
Great m8, thanks
That will be useful
BTw, already rated you :D