Results 1 to 4 of 4

Thread: Advanced Winsock

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Question

    Hi;

    Lately I was asked to write a Server/MultiClient Instant Messenging application for my company. I figured out "Easy"

    coz I already Wrote a peer to peer chat application before and it worked well.

    I used this time TCP for transmitting info. Here is the way it Goes :

    - Server Runs on NT IIS Platform
    - ClientApps Run with Windows98 on Employee WorkStations.
    - ClientApps Send identification Msg on StartUp
    - Server updates DB
    - Client Exchange Msgs Via Server ...


    Ok that is basically what it does, pretty classic... Now it is up and running , but during developpment I faced some Unexpected Problems with winsock ...

    Sometimes 2 different Chuncks of data arrive Concatinated as if they were one.

    Sometimes the second DataPacket Doesnt Get there at all.

    Even when I am sending the same data to different Client (each Client has his own Dedicated Winsock Control) through a simple loop .. the data sometimes wont get to some Clients.

    The weirdest I have ever experienced was while debugging the client app , I ran the server on a different Computer (Server) then I started Debugging the Client. Sometimes when I terminate the client And run it back again I get Bunch of data I sent to myself in the Previous Run.


    To make things work th way I want I used the winsock SendComplete() event, to resume Data Transmition.

    Till now No problem has been reported ... But I would like to understand The Whys and Hows of winsock in order not to face the same problems next time . I know about Buggs in Winsock Control but if anyone knows Really how it works and can explain why I have been having these Problem. Please Help.

    I hope I havent Bored you with the Description ButI wanted you Guys to know the Max in order to help

    - thank you in advance -
    - regards -
    - razzaj -

  2. #2
    Guest
    Sometimes 2 different Chuncks of data arrive Concatinated as if they were one.

    Sometimes the second DataPacket Doesnt Get there at all.

    Even when I am sending the same data to different Client (each Client has his own Dedicated Winsock Control) through a simple loop .. the data sometimes wont get to some Clients.

    The weirdest I have ever experienced was while debugging the client app , I ran the server on a different Computer (Server) then I started Debugging the Client. Sometimes when I terminate the client And run it back again I get Bunch of data I sent to myself in the Previous Run.
    When you use SendData, the data doesn't get sent the instant the instruction is performed, it takes abit of time before it is sent. So if you use something like:

    Code:
    Winsock1.SendData "Test"
    Winsock1.Close
    is unlikely to work as Winsock1 would have been closed before the send was finished. Similarly, if you are doing:

    Code:
    For i = 0 to NumberOfClients
       Winsock1.SendData YourData
    Next i
    You can't be sure that the packet will get sent before the next time the loop comes back.

    Also, SendData doesn't always do what you tell it to if you have two of its commands together, just as when you send a large file Winsock is likely to break it up, it might join two strings together if you do:

    Code:
    Winsock1.SendData "1"
    Winsock1.SendData "2"
    Just as you said, the most foolproof way out is using the SendComplete event. However, this usually requires alot more code if the types of data being sent/received varied alot (if its simple stuff, I will use Sleep or a loop of DoEvents.

    Sunny

  3. #3

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    yes I know but also when I am using the following code it sometimes ****s up <--sorry for that:

    Code:
      For i = 0 to NumberOfClients
       Winsock1(i).SendData MyData
      Next i
    - regards -
    - razzaj -

  4. #4
    Guest
    As I explained, by putting two or more SendDatas together, Winsock might join it just as it breaks things up. When you loop the SendData in the way you did, it is almost the same as putting them together.

    Code:
    For i = 0 to 3
       Winsock1.SendData "Test"
    Next i
    Is almost the equiv of

    Code:
    Winsock1.SendData "Test"
    Winsock1.SendData "Test"
    Winsock1.SendData "Test"
    Winsock1.SendData "Test"

    Your two (I can think of) solutions is to use the foolproof but longer way of SendComplete or put a small wait after the SendData which will give it time to send the data before the loop comes back.

    Sunny

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