Socket.send
Regan Heath
regan at netmail.co.nz
Tue Sep 27 03:53:30 PDT 2011
On Tue, 27 Sep 2011 11:20:32 +0100, Andrea Fontana <advmail at katamail.com>
wrote:
> It's a small server (http) so I don't wait for any reply from the
> client. If there's an header "connection: close", server should
> close connection when data is sent.
>
> So on server side i should write:
>
> if (httpRequest.isCompleted)
> {
> // Parsing request headers
> [... omitted ...]
> // Build http reply
> [... omitted ...]
>
> socket.send(reply);
> socket.shutdown(SocketShutdown.BOTH);
> }
>
>
> and then wait for client to close connection?
Almost. If the client sends additional data which you do not read above,
then shutdown(BOTH) may cause a "connection aborted" error on the client
end. Ideally you want to shutdown(SEND) only, then loop reading all
remaining data from the socket (until receive returns 0), then call
close().
I've just looked at std.socket and I can't see a nice easy way to call
select on just the one/current socket.. I was expecting
socket.select(READ|WRITE|EXCEPT) helper functions or similar :(
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list