Ok. I have a .NET (in C#) service that needs to make connection to a projector through TCP. It serves as a back end to a GUI. Reason why it is this way is because I need the GUI to show up just under the login prompt. The idea is that anyone can use the projector w/o having the need to log in to the machine (say to play a DVD). The service is set to start automatically.
The problem:
I keep getting System.IO.IOException: System unable to write data to the transport connection: an existing connection was forcibly closed by the remote host. Now here's the kicker. If I login to the machine and kill the service and then turn it back on, everything runs hunky dory. I can turn the damn thing on/off and what not. And it works for every single subsequent login/logout until the next reboot.
Here's the code that throws the exception.
This baffles me since .CanWrite should be returning false if the connection was closed.
Edit: The service throws the exception not the GUI.
The problem:
I keep getting System.IO.IOException: System unable to write data to the transport connection: an existing connection was forcibly closed by the remote host. Now here's the kicker. If I login to the machine and kill the service and then turn it back on, everything runs hunky dory. I can turn the damn thing on/off and what not. And it works for every single subsequent login/logout until the next reboot.
Here's the code that throws the exception.
Code:
//m_ns is a NetworkStream object try { //Write to the port but have to convert string -> byte[] if (m_ns.CanWrite) { m_ns.Write(Encoding.ASCII.GetBytes(cmd), 0, cmd.Length); } else { LogFile.WriteLog("!ERROR! OnscreenService: Unable to write to the socket"); return false; } return true; } catch (SocketException se) //Exceptions for sockets { //There is code here but I don't think it is relevant to this issue. } catch (System.IO.IOException ioe) //Exceptions for NetworkStream { LogFile.WriteLog(string.Format("!ERROR! Onscreenservice (System.IO.IOException): {0} {1}", ioe.Source, ioe.Message, ioe.StackTrace)); return false; }
This baffles me since .CanWrite should be returning false if the connection was closed.
Edit: The service throws the exception not the GUI.
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.