Hello people i am currently writting myself an app where i need a tcp/ip connection Currently all is working except for one thing
both the socket.connected, StreamReader.canread and StreamWriter.canwrite always return true even if my other app is totaly turned off and disconnected.......
ofcourse this is rather odd and i am wondering if i did something wrong OR that there is a fix to all this :S
this is just the "server" side part of the socket readSocket checks for packages from the client party and doClose() makes sure all controlls are closed and set to null again. But the code never even reaches it.Code:IPAddress localAddr = IPAddress.Parse("127.0.0.1"); ConnectionListener = new TcpListener(localAddr,port); ConnectionListener.Start(); ConnectionClientSocket = ConnectionListener.AcceptSocket(); if(ConnectionClientSocket.Connected) { ConnectionListener.Stop(); ConnectionStream = new NetworkStream(ConnectionClientSocket); ConnectionReader = new StreamReader(ConnectionStream); ConnectionWriter = new StreamWriter(ConnectionStream); //RAISE Connected(); //END RAISE while(ConnectionStream.CanWrite && ConnectionStream.CanRead && ForceDisconnect == false) { readSocket(); ConnectionWriter.Flush(); System.Windows.Forms.Application.DoEvents(); } } doClose();
(also the while loop contained ConnectionClientSocket.connected etc but this is the current thing i am trying)
edit:
If there is someone with a Fully 100% working socket for C# which doesn't need any non .net controls i am happy with that too :P




Reply With Quote