Scratch this folks, sorry to be a bother if anyone read their way through this. What appeared to be a totally unrealistic and obscure problem ended up being a my own fault. Looks like I had a thread conflict. Dumb.
Just for everyone's reference if you run into anything similar, watch out for StreamReader.ReadToEnd( ) - Never finishes on SocketStream's. Thanks anyway ladies and gents. On Aug 27, 11:49 am, "A. Anderson" <[email protected]> wrote: > Good afternoon. > > I've got some socket code that I appear to be having some problems > with. I've taken a few approaches at it and come up short more than > once... Here is what LOOKS like it ought to be the solution; > > public void Start() > { > this.SetRunning(true); > > while (this.IsRunning()) > { > if (!this.Client.CheckConnection()) > { > return; > } > else > { > String Line = null; > while ((Line = > this.Client.ClientReader.ReadLine()) != null) > { > // Do some kind of input handling. > } > continue; > } > } > } > > Here is how my stream/reader/writer are built: > > this.ClientSocket = ClientSocket; > this.ClientStream = new > NetworkStream(this.ClientSocket); > this.ClientReader = new > StreamReader(this.ClientStream); > this.ClientWriter = new > StreamWriter(this.ClientStream); > > Here is what I am experiencing: > > Over every iteration of the loop inside of this threads main function, > the program hangs at ClientReader.ReadLine - this makes perfect sense > to me. Waiting for a line to be fed. Fair. > What DOESN'T make sense is that after I send a line ( currently using > putty on both a raw and telnet connection ) it catches that I sent a > line, but does not read the text that was actually sent - An example: > Start the server > Allow initiation > Connect client > Send 'request\n\r' To Client > Recieve 'request\n\r' from server > Send 'test\n\r' to server > Recieve '\n\r' from client > > Here is where I initialize my server socket that accepts all of our > connections: > > public Boolean StartServer() > { > if ( this.ListenerInstance != null && > this.ListenerInstance.IsRunning()) > { > return true; > } > else > { > this.ListenerInstance = new SocketListener(this); > this.ListenerThread = new > Thread(ListenerInstance.Start); > this.ListenerThread.Start(); > > while (ListenerInstance.IsRunning() && ! > ListenerInstance.IsBound()) > { > this.Status = "Waiting to bind host socket..."; > } > return true; > } > } > > And accepting new clients: > ( this happens in the listener thread... ) > > public void AcceptConnections() > { > if (this.HostListener == null) > { > return; > } > else > { > // Just changed this to AcceptTcpClient from > AcceptSocket - no difference. > Socket NewConnection = > this.HostListener.AcceptTcpClient( ).Client; > ClientData AcceptingClient = null; > > if ((AcceptingClient = > this.Server.GetClientData(NewConnection.RemoteEndPoint.ToString().Split(':' ) > [0])) == null) > { > this.Server.AdditionalStatus += "\n\rCould not > accept connection from " + > NewConnection.RemoteEndPoint.ToString().Split(':')[0] + " : Not listed > as an available client."; > } > else > { > this.Server.AdditionalStatus += "\n\rNew > connection accepted from " + > NewConnection.RemoteEndPoint.ToString().Split(':')[0] + "."; > AcceptingClient.Accept(NewConnection); > return; > } > } > return; > } > > If anyone can help that'd be great, and much appreciated.
