Re: Clarification please

Tech-Archive recommends: Fix windows errors by optimizing your registry



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;
>
> }
>
>


.



Relevant Pages

  • Re: Issue with multiple threads and System.Net.Sockets.Socket
    ... first off your app has a 200 loop count, I am pritty sure you can only throw ... private thd as system.threading.thread ... private eip as string ... Are you closing the socket out? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with OnReceive method
    ... > I' m developing a multithread application with a socket network ... > continuosly Receive in the thread socket loop. ... > this one start the server thread. ... when a connection arrived it start a new childthread and ...
    (microsoft.public.vc.mfc)
  • Re: Socket mit Network-Byte-Order (Motorola-Format)- Client und Server
    ... dass Du mit dem eigenen Server den eigenen Code testest. ... Connection z.b. zwischen Read und WriteTelegram. ... Socket serverSocket = new Socket( ... string request = ReadTelegram; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: GNAT.Sockets. Blocking?
    ... some servers to prevent robot or programs ... request some browsers information or they close the connection. ... end loop ... I'm kind of new to socket programming and I need some help here. ...
    (comp.lang.ada)
  • Re: tcp connection in gui: event based
    ... Write a small proc that does the accept and sets the connection to ... Use to register procs that get fired when the socket is ... If you have a full line, send it to the GUI, maybe dispatching via ... after to not block the event loop if its a bit bigger ...
    (comp.lang.tcl)