Results 1 to 5 of 5

Thread: Problem with Winsock Control

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    57

    Lightbulb Problem with Winsock Control

    I am trying to develop an online application using VB 6.0, and i use the winsock control to handle communication of my application. Sorry i have to write this much, i can't explain it shortly to justify my problems due to language barrier.

    When i invoke the winsock.senddata method once, i am able to send the data i want, however, when i invoke the winsock.senddata twice in a procedure(or a loop), the message that is sent becomes the sum of two senddata, looks like this:
    winsock1.senddata "ABC"
    'somewhere else in the procedure later...
    winsock1.senddata "DEF"

    'at the client side
    winsockclient.getdata msg
    'msg becomes "ABCDEF"

    I manage to solve problem like this, by putting a Doevent between the first and second senddata. However, i encountered the same problem again when....

    winsock1.senddata "ABC"
    Doevents
    Winsock1.senddata "DEF"
    Doevents
    for i = 1 to 5
    winsock1(i).senddata "GHI"
    doevents
    next i

    On the client side, the first message "ABC" is received , but the second and third message gets jumbled up again, even when i put Doevents before the loop, sometimes it doesn't sometimes it does, i think the only explanation is when senddata is invoked, the control turn into "Sending" status, putting doevents will allow other procedure to be processed first before going to the next statement, therefore will solve my problem temporarily.

    However (again), my app is meant for internet usage, sometimes a lag will force my control to be in "sending" status longer.

    I thought about the problem and i think the only solution is to make a buffer for the senddata method, using arrays, meaning that i will output the data to an array whenever i want to senddata, and send the data on the first index of the array with a timer constantly checking if there's anything in the array to send.

    Problems with my solution: Have to make a loop to move the data in second array to the first, the third to second, when data is being sent, not feasible when i have multiple winsock control running and will cause a major lag when there are too much data to be sent.

    Please let me know if you know a solution to my problem, thank you.

  2. #2
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I had the same question and it is still unanswered.
    Last edited by wasiq; Jun 3rd, 2001 at 11:55 AM.

  3. #3
    magadass
    Guest
    Thats because the winsock recieves data in chunks not sequentially...In order for that to work how you want it to you will have to come up with a type of "language" between your server and client program to exchange data..I have made many programs in winsock and when I did my client/server I used a format similar to the example below:

    Winsock1.sendata "RECV " & i & DATA GOES HERE & vbnewline & vbnewline

    i represents an incrementing number..Everytime you send you will increment this number...Then you will parse the data using RECV and the number as the first point to cut off and the two line feeds at the end to cut off and you have your data..you can use anyformat you want...Just parse the data apart when you recieve it...

    This is only if you are using a Global Variable to recieve your data in winsock though...If you declare your variable within the scope of RecieveData event everytime you recieve data the variable will be cleared and the new data will be placed into it..

    Later..

  4. #4

    Thread Starter
    Member
    Join Date
    May 2001
    Posts
    57

    Thanks for the Tip!!

    Took me a while to understand that but i finally made it

    I used a special character "³"( ALT 05555) as a delimiter between my messages and i break em up upon receiving them

    Thanks alot

  5. #5
    winsock.senddata "My Text" & vbcrlf

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