Sockets and Streams

okibi spam at ratedo.com
Sun Apr 6 06:45:02 PDT 2008


Tobias Kieslich Wrote:

> 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.

It's not that function. That function is used by the server and works just fine. However, I want clients to be able to connect and send a param to that function.

The problem is that once the client connects and calls the function, it varies how much of the function will run prior to it crashing. For example, in the function I'm doing three things: writing to a file, adding to a window on the server, and then changing some other data. It varies how far through this process it can get and I don't know why. Sometimes (but only on the first connect) it will do the whole process fine.

Is the client disconnecting too soon? Is the server not listening correctly? I just don't see what's wrong!

What all would you need to see?


More information about the Digitalmars-d-learn mailing list