Results 1 to 19 of 19

Thread: Data sending Winsock problem?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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?
    Thanks for helping me out.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; Nov 24th, 2008 at 05:52 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Data sending Winsock problem?

    well yeah i wrote it wrong for the winsock
    this is what i got

    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
    Thanks for helping me out.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.
    Last edited by jmsrickland; Nov 24th, 2008 at 06:16 PM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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
    Thanks for helping me out.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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..
    Thanks for helping me out.

  7. #7
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Data sending Winsock problem?

    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)

    txtPostW.Text = txtPostW.Text & strResponse

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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
    Last edited by batori; Nov 25th, 2008 at 04:16 AM.
    Thanks for helping me out.

  9. #9
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    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.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.
    Thanks for helping me out.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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?
    Thanks for helping me out.

  12. #12
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Data sending Winsock problem?

    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.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.
    Last edited by batori; Nov 25th, 2008 at 11:20 AM.
    Thanks for helping me out.

  14. #14
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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?

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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?
    Thanks for helping me out.

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.
    Last edited by jmsrickland; Nov 25th, 2008 at 04:44 PM.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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
    Thanks for helping me out.

  18. #18
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Data sending Winsock problem?

    Great m8, thanks
    That will be useful


    BTw, already rated you
    Thanks for helping me out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width