Sockets and Streams

Tobias Kieslich tobias at justdreams.de
Fri Apr 4 22:43:53 PDT 2008


Hi, I think people need a bit more information, the code looks okay to
me, but what is srvCMD doing? Is that crashing? Does it have a return
value? Did you try wrapping it into a try, catch statement? My mony is on
this function.

	-T
On Fri, 04 Apr 2008, okibi wrote:

> okibi Wrote:
> > 
> > My question is this: Even though it usually connects just fine, once I
> > verify that the connection is made and try to hit a function on the
> > server side via the server portion, it will either run part of it,
> > or none of it and crash. Am I maybe doing it wrong? This is my current
> > code:

> > server:
> > auto soc = new TcpSocket();
> > soc.bind(new InternetAddress("localhost", 10101));
> > soc.listen(10);
> > while (true)
> > {
> > 	Socket clientSocket = soc.accept();
> > 	Stream str = new SocketStream(clientSocket);
> > 	if(clientSocket.isAlive())
> > 	{
> > 		char[] line = str.readLine();
> > 		clientSocket.close();
> > 		if(line !is null)
> > 		{
> > 			srvCMD(replace(line, "\n", ""));
> > 			line = null;
> > 		}
> > 		clientSocket.close();
> > 	}
> > }

> 
> Sorry, the first clientSocket.close() shouldn't be there in the server code.


More information about the Digitalmars-d-learn mailing list