Socket programming with Cygwin

Brian Dessent
Wed Dec 3 10:56:00 GMT 2008

John Emmas wrote:

> In every case, the programs fail when the client attempts to connect to the
> server.  This would be a typical line:-
> status = ::connect ( m_sock, ( sockaddr * ) &addr, sizeof ( addr ) );
> 'status' receives -1 and if I check the error it's invariably something like
> "Connection refused" (assume for the sake of argument that the supplied
> parameters are valid because the same programs work fine under Linux).

The call fails because addr is junk, because the demo passed "localhost"
to inet_pton.  According to the docs, this function only takes IP
addresses.  If you change simple_client_main.cpp to use an IP address
instead of localhost the example works for me.  (It should really be
modified to do a hostname lookup.)  This example really isn't that great
in that it's apparently relying on some non-standard behavior of glibc's

> Do I need to enable something in Cygwin for sockets to work?  e.g. should
> I have previously run a service using cygrunsrv?  I'm running out of things
> to try and there seems to be very little that could go wrong.  I'd be
> grateful for any suggestions.  Thanks

No, you don't need to install any service to use regular sockets.  The
plethora of network tools in the distro (e.g. apache, curl, openssh,
proftpd, lftp, wget, etc) that use sockets and that build without any
special modifications should be an indication that this should just


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list