Socket packages

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ole

    Socket packages

    Hi,

    Is there a way to prevent Socket from assembling the packages it receives?
    short explanation:
    I have an application A that sends like this:
    for (i0; i<4; i++)
    {
    MySendSocket.se nd(sendBuffer, count, SocketFlags.Non e);
    }

    ....and a receiving application that receives like this:
    while(MyReceive Socket.connecte d)
    {
    noOfBytesReceiv ed = MyReceiveSocket ..Receive(recei veBuffer);
    DoSomething.... ......
    }

    first time it receives 10 bytes but then it receives the last 30 bytes in
    one package (noOfBytesRecei ved =30). So is there a way to force it to
    receive the individual packages (the size is not necessarily the same in
    each package)?

    Thanks,
    Ole


  • SirMike

    #2
    Re: Socket packages

    Dnia Thu, 2 Nov 2006 14:34:40 +0100, Ole wrote:

    Packet fragmentation is a normal thing and depends on many things.
    I recommend to read about TCP/IP.

    --
    SirMike - http://www.sirmike.org

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but
    when you do, it blows away your whole leg. - Bjarne Stroustrup

    Comment

    • Ole

      #3
      Re: Socket packages

      Hi again,

      Some sort of method to block sender would do it, but is such a method
      available?:
      while(MyReceive Socket.connecte d)
      {
      noOfBytesReceiv ed = MyReceiveSocket ..Receive(recei veBuffer);
      MyReceiveSocket . BlockSender() <----- ????
      DoSomething.... ......
      }

      Thanks,
      Ole


      "Ole" <ole@blabla.com wrote in message
      news:ufC6rOo$GH A.3308@TK2MSFTN GP03.phx.gbl...
      Hi,
      >
      Is there a way to prevent Socket from assembling the packages it receives?
      short explanation:
      I have an application A that sends like this:
      for (i0; i<4; i++)
      {
      MySendSocket.se nd(sendBuffer, count, SocketFlags.Non e);
      }
      >
      ...and a receiving application that receives like this:
      >
      first time it receives 10 bytes but then it receives the last 30 bytes in
      one package (noOfBytesRecei ved =30). So is there a way to force it to
      receive the individual packages (the size is not necessarily the same in
      each package)?
      >
      Thanks,
      Ole
      >

      Comment

      • Jianwei Sun

        #4
        Re: Socket packages

        Ole wrote:
        Hi,
        >
        Is there a way to prevent Socket from assembling the packages it receives?
        short explanation:
        I have an application A that sends like this:
        for (i0; i<4; i++)
        {
        MySendSocket.se nd(sendBuffer, count, SocketFlags.Non e);
        }
        >
        ...and a receiving application that receives like this:
        while(MyReceive Socket.connecte d)
        {
        noOfBytesReceiv ed = MyReceiveSocket ..Receive(recei veBuffer);
        DoSomething.... ......
        }
        >
        first time it receives 10 bytes but then it receives the last 30 bytes in
        one package (noOfBytesRecei ved =30). So is there a way to force it to
        receive the individual packages (the size is not necessarily the same in
        each package)?
        >
        Thanks,
        Ole
        >
        >
        The easy answer is that "No, you cannot".

        You have to separate the messages by yourself. There are normally 2 ways:

        1put the number of messages size as part of the header,so you know
        exactly how much you want to read.
        2use some delimiter like SOT (Start of Text), EOT(End of Text) to
        separate your message.

        J.W.

        Comment

        Working...