Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com X-Originating-IP: [152.10.19.134] From: "A. Dalton" To: cygwin AT sources DOT redhat DOT com Subject: AF_UNIX Socket Programming Date: Mon, 21 Aug 2000 10:39:14 EDT Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 21 Aug 2000 14:39:14.0656 (UTC) FILETIME=[93E6AE00:01C00B7D] Greetings, I have been able to install Cygwin (thanks to the nice little setup program). Now I am trying to do some basic AF_UNIX socket programming. I have copied an example from the following URL: http://www.informatik.hu-berlin.de/~mueller/dsm/www.wrox.com/books/680/680.html In this example, a server and a client that communicate via a socket. Everything compiles correctly but when I run it, nothing happens. It appears that the accept() in the server fails. Whenever I include the printf() for "server waiting," I see that I'm in a hard loop. The accept() doesn't seem to block. The exact same code works in Linux. Here's the code I'm using: //********************************************************************** // // Server.cpp // #include #include #include #include #include int main() { int server_sockfd; int client_sockfd; int server_len; int client_len; sockaddr_un server_address; sockaddr_un client_address; unlink("server_socket"); server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); server_address.sun_family = AF_UNIX; strcpy(server_address.sun_path, "server_socket"); server_len = sizeof(server_address); bind(server_sockfd, (sockaddr*)&server_address, server_len); listen(server_sockfd, 5); while(true) { char ch; // printf("server waiting\n"); client_sockfd = accept(server_sockfd, (sockaddr*)&client_address, &client_len); read(client_sockfd, &ch, 1); ++ch; write(client_sockfd, &ch, 1); close(client_sockfd); } } //********************************************************************** // // Client.cpp // #include #include #include #include #include int main() { int sockfd; int len; sockaddr_un address; int result; char ch = 'A'; sockfd = socket(AF_UNIX, SOCK_STREAM, 0); address.sun_family = AF_UNIX; strcpy(address.sun_path, "server_socket"); len = sizeof(address); result = connect(sockfd, (sockaddr*)&address, len); if(result == -1) { perror("oops: client1"); exit(1); } write(sockfd, &ch, 1); read(sockfd, &ch, 1); printf("char from server = %c\n", ch); close(sockfd); exit(0); } //********************************************************************** ad24482 AT GARIBALDI ~ $ g++ -Wall -o server server.cpp ad24482 AT GARIBALDI ~ $ g++ -Wall -o client client.cpp ad24482 AT GARIBALDI ~ $ server& [1] 1015 ad24482 AT GARIBALDI ~ $ client // In theory, I should see "char from server = B" here The server does seem to create the socket file: ad24482 AT GARIBALDI ~ $ ls -lap server_socket srw-r--r-- 1 ad24482 unknown 15 Aug 21 10:30 server_socket= ad24482 AT GARIBALDI ~ $ g++ --version 2.95.2 ad24482 AT GARIBALDI ~ $ If anyone has any idea what is wrong, I could really use some help. Thanks in advance for your time. Andy ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com