Results 1 to 5 of 5

Thread: Using Winsock to send data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Peterborough, Cambs, England
    Posts
    176

    Post

    Hi

    I'm having some trouble sending data with winsock.

    My client application will send data to my server application.

    I user TCPconnect.SendData ("abc...") etc.

    I use a sub proecdure to find out what the client has send. All messages are prefixed with a 5 character code.

    Then the server will do something according to what it recieved.

    The problem I get is that sometimes the client needs to send 2 bits of data.

    i.e.

    TCPconnect.SendData ("blah blah")
    TCPconnect.SendData ("blah2 blah2")

    But the server will recieve "blah blahblah2 blah2"

    Is there anyway to make sure that the data has been sent before it sends the next string?

    I've tried putting DoEvents inbetween the two SendData commands, but that doesn't work.


  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Peterborough, Cambs, England
    Posts
    176

    Post

    Guys...


    This is getting realy urgent!


  3. #3
    New Member
    Join Date
    Jul 1999
    Posts
    15

    Post

    Reset the connection in between your sends.
    It's a good idea when using winsock to close your connection when it is not needed.

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    A couple of strategies I use are to add a control character to the end like vbcrlf and have the server look for it when data comes in, or have the first character be a count character to say how much text is comming.

    eg if less than 256 characters then

    Sendtxt = "The string I want to send"
    TCP.Senddata CHR(Len(Sendtxt)) & Sendtext
    Then at the server use asc(left(data,1)) to get the number of arrived characters.

    Remember the reason that these are necessary is that you are using packets and buffers and winsock might send data when a buffer is full (before you're ready) or hold the data a little till more comes. Both the above work best together, the VbCrLf to copy arrived data out of the buffer at the time of the message end and the chr() count to process it.

    It helps to have a few send/recieve processing functions prepared for a text->winsock app

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    Peterborough, Cambs, England
    Posts
    176

    Post

    Thanks guys!

    You've just saved my life, (ish).


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