Sockets issue
Raynor
memphis007fr at yahoo.fr
Tue Jan 15 04:31:10 PST 2008
okibi a écrit :
> I'm a bit puzzled here. I'm trying to get my sockets working, but it only connects once. Here is my code:
>
> server.d:
> auto soc = new TcpSocket();
> soc.bind(new InternetAddress("localhost", 10101));
> soc.listen(10);
> Stream str = new SocketStream(soc.accept());
> while(true)
> {
> char[] line = str.readLine();
> if (line !is null)
> cmdOpen(line);
> }
>
> client.d:
> Socket socket = new TcpSocket(new InternetAddress("localhost", 10101));
> Stream stream = new SocketStream(socket);
> stream.writeString(args[1]);
> socket.close();
>
> Can anyone point out what I'm doing wrong? The first connection works fine, but any connection afterwords fails (line IS null on second connection).
>
> Thanks!
while (true)
{
Socket clientSocket = soc.accept();
Stream str = new SocketStream(clientSocket);
while(clientSocket.isAlive())
{
char[] line = str.readLine();
if (line !is null)
cmdOpen(line);
}
}
More information about the Digitalmars-d-learn
mailing list