Re: Clarification please
- From: "Dan" <dvazanias@xxxxxxx>
- Date: Mon, 23 Jan 2006 13:11:25 -0000
Sorry writing the last post i did figure out the answer, in my loop as i
read the string i escape the loop on reading a 0, so i needed to
reinitialise my byte array in there which i wasn't doing which is why the
old rubbish persisted, damn monkeys!
Thanks guys
--
Dan
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:e4Xy9b4HGHA.3856@xxxxxxxxxxxxxxxxxxxxxxx
> Hi
>
> I made a simple tcp client server app using tcplistener / tcpclient in c#
>
> All runs great apart from one slight issue,
>
> If i write say "hello world" to the data stream and send the server shows
> "hello world"
>
> when i then write "monkey" i get this at the server end "monkeyworld";
>
> So part of the first data sent has remained?
>
> Is it the sevrer end retaining the datastream or is the client retaining
> and resending it but just overwriting the first bit?
>
> Also in the examples i work through it seems to open a new socket
> connection, send data, close the socket and repeat. Surely i should open a
> socket, keep it open send data after data for the duration of the
> client/server connection and then when finished close the socket? Or is
> that wrong?
>
> I use this code in a new thread to handle the socket connection:
>
> public void handlerThread()
>
> {
>
> Socket handlerSocket = (Socket)_alSockets[_alSockets.Count-1];
>
> NetworkStream netStrm = new NetworkStream(handlerSocket);
>
> int thisRead=0;
>
> int blockSize = 1024;
>
> Byte[] dataByte = new Byte[blockSize];
>
> lock(this)
>
> {
>
> while(true)
>
> {
>
> thisRead = netStrm.Read(dataByte,0,blockSize);
>
> string txt = Encoding.ASCII.GetString(dataByte,0,blockSize);
>
> lbConnections.Items.Add(txt);
>
> if(thisRead==0)
>
> break;
>
> }
>
> }
>
> handlerSocket = null;
>
> }
>
>
.
- References:
- Clarification please
- From: Daniel
- Clarification please
- Prev by Date: Re: Clarification please
- Next by Date: Re: Design question
- Previous by thread: Re: Clarification please
- Next by thread: Re: socket IOControl error 10022?
- Index(es):
Relevant Pages
|