sgt_pinky
Regular
I have this problem when I am writing and reading network streams. If I send another packet, then it will also send the last packet again, so I end up sending more and more information. Somehow I mustn't be flushing the buffer out correctly or something. This is my output if I click a button 3 times - you can see by the third time it has sent the packet 3 times, and hence the server replies 3 times.
To send a packet I am using:
To receive a packet I am using:
I have tried closing the stream after I have finished writing, but that seems to destroy the socket. I have tried Flush() too, but not too sure how to use that one.
Cheerio,
Pinky
Recieved packet: hs#USHOEOZSSUNW
Connection verified.
Recieved packet: hs#YTZJCYVGGWRX
Recieved packet: hs#YTZJCYVGGWRX
Connection verified.
Connection verified.
Recieved packet: hs#THPQVRMIHKML
Recieved packet: hs#THPQVRMIHKML
Recieved packet: hs#THPQVRMIHKML
Connection verified.
Connection verified.
Connection verified.
To send a packet I am using:
Visual Basic:
Dim ns As NetworkStream = Client.GetStream
If ns.CanWrite Then
Dim bytes() As Byte = Nothing
bytes = System.Text.Encoding.UTF8.GetBytes(Msg)
ns.Write(bytes, 0, bytes.Length)
End If
To receive a packet I am using:
Visual Basic:
Dim ns As NetworkStream = cli.GetStream
If ns.CanRead And ns.DataAvailable Then
Dim bytes(cli.ReceiveBufferSize) As Byte
ns.Read(bytes, 0, cli.ReceiveBufferSize)
RaiseEvent NewPacket(cli, System.Text.Encoding.UTF8.GetString(bytes))
Else
cli.Close()
Connections.Remove(cli)
RaiseEvent ClientMessage("Client connected from " & cli.Client.RemoteEndPoint.ToString.Split(":")(0) & " has disconnected.")
End If
I have tried closing the stream after I have finished writing, but that seems to destroy the socket. I have tried Flush() too, but not too sure how to use that one.
Cheerio,
Pinky