Sending messages using socket
nrgyzer
nrgyzer at gmail.com
Sun Jul 24 10:12:48 PDT 2011
Hi guys,
I'm trying to work with sockets but I've some trouble with them. I
implemented a really simple Socket which should simply send a text
message after accepting the request. My code is the following:
module server;
import std.socket;
void main() {
TcpSocket server = new TcpSocket();
server.bind(new InternetAddress(8080));
server.listen(1);
while(true) {
Socket cs = server.accept();
cs.send("test");
}
}
When I start my small sample application and tries to connect (http://
localhost:8080) to them using a browser I don't get any message. It
seems to work forever and sometimes I get my message "test", but the
connection between my browser and my application won't finished.
When I add cs.close() after cs.send("test"), the connection will be
closed, but I don't get any message in my browser - the browser says
that the service isn't available (error-page).
What's wrong with my code? => Thanks for any help :)
More information about the Digitalmars-d-learn
mailing list