Buffer overlap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth H. Young

    #1

    Buffer overlap

    I am getting over lapping data while sending and receiving data in a tcp listener I am working on. How does one reset or clear the buffer or bytes so they don't carry over to the next send or receive?

    Thanks in advance!

    Partial Example:

    ' Client sends:
    TempS = curAdd.ToString & ".............. ............... ............... ............... ............... ............... ............"

    ' Padding the end of the IP address so I can trim(".") when received because I couldn't trim the free space at the end.

    Buffer = System.Text.Enc oding.Default.G etBytes(TempS.T oString)

    Client.GetStrea m().Write(Buffe r, 0, Buffer.Length)



    ' The Server Receives:

    While Not StopListener

    If CurSocket.Avail able > 0 Then

    ' 1. Receive IP Address from client:

    Bytes = CurSocket.Recei ve(Buffer, Buffer.Length, 0)

    SyncLock CurThread

    clientV = (System.Text.En coding.Default. GetString(Buffe r)).ToString

    clientV = clientV.Trim(". ")

    Buffer.Clear(Bu ffer, Buffer.Length, 0)

    On the next send / receive I am getting leftover ........... in the string.

    THANKS!

  • Mattias Sjögren

    #2
    Re: Buffer overlap

    Kenneth,

    I'm not sure I understand the problem, but ...

    [color=blue]
    >Buffer = System.Text.Enc oding.Default.G etBytes(TempS.T oString)[/color]

    I'd recommend using an encoding other than Default (such as UTF-8),
    because the default can be different on different systems.

    [color=blue]
    >Buffer.Clear(B uffer, Buffer.Length, 0)[/color]

    Since you specify a length of xero here, nothing will be cleared.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Kenneth H. Young

      #3
      Re: Buffer overlap

      When I send this: TempS = curAdd.ToString &
      ".............. ............... ............... ............... ............... ............... ..........."
      to the server I then trim(".") to get rid of the periods. Then the server
      sends four messages back to the client depending on the processes that takes
      place. Finally the client Sends: "PCNAME-Scheduled" to the server and the
      server receives "........ti ng". It appears as though its pieces of previous
      buffer information.

      I hope I explained the issue!

      Thanks for the HELP!





      "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
      news:eWMTwuP0FH A.3488@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Kenneth,
      >
      > I'm not sure I understand the problem, but ...
      >
      >[color=green]
      >>Buffer = System.Text.Enc oding.Default.G etBytes(TempS.T oString)[/color]
      >
      > I'd recommend using an encoding other than Default (such as UTF-8),
      > because the default can be different on different systems.
      >
      >[color=green]
      >>Buffer.Clear( Buffer, Buffer.Length, 0)[/color]
      >
      > Since you specify a length of xero here, nothing will be cleared.
      >
      >
      >
      > Mattias
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      > Please reply only to the newsgroup.[/color]


      Comment

      • Peter Huang [MSFT]

        #4
        Re: Buffer overlap

        Hi

        Firstly I think you may try the code in the link below for client/server.
        TcpListener Class
        http://msdn.microsoft.com/library/de...us/cpref/html/
        frlrfsystemnets ocketstcplisten erclasstopic.as p
        TcpClient Class
        http://msdn.microsoft.com/library/de...us/cpref/html/
        frlrfSystemNetS ocketsTcpClient ClassTopic.asp

        If you still have any concern, can you build a simple reproduce sample and
        send to me via removing "online" from my email address.

        Best regards,

        Peter Huang
        Microsoft Online Partner Support

        Get Secure! - www.microsoft.com/security
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        Working...