delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/12/03/05:56:11

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <493665A0.6F1DE647@dessent.net>
Date: Wed, 03 Dec 2008 02:55:28 -0800
From: Brian Dessent <brian AT dessent DOT net>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Socket programming with Cygwin
References: <003201c9552c$a57b1a00$4001a8c0 AT mycomputer>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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
inet_pton.

> 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
work.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019