Sockets and Streams

okibi spam at ratedo.com
Tue Apr 8 02:39:39 PDT 2008


Tobias Kieslich Wrote:

> On Sun, 06 Apr 2008, 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();
> > 		if(line !is null)
> > 		{
> > 			srvCMD(replace(line, "\n", ""));
> > 			line = null;
> > 		}
> > 		clientSocket.close();
> > 	}
> > }
> > 
> > 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!
> okay, I'm getting confused here so I wanna make sure I get it right:
> if the client connects, and sends one command the srvCMD function
> triggers more than one action, or is each actiontriggred by a different
> command? In the latter case I probably would use a select() based server
> that monitors the socket.
> 
> 	-Tobias

It triggers one command, but the server is required to do many things with that one command.

I just need the server to receive a string from any given client and be able to do a few things with it. The client doesn't need to remain connected.


More information about the Digitalmars-d-learn mailing list