From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alex Sassmannshausen Newsgroups: gmane.lisp.guile.user Subject: Unix Domain Sockets and (write) (read) Date: Wed, 03 Jul 2013 00:31:23 +0200 Message-ID: <87y59o61c4.fsf@honeybear.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1372800725 4134 80.91.229.3 (2 Jul 2013 21:32:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Jul 2013 21:32:05 +0000 (UTC) To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Jul 02 23:32:06 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uu8BB-000429-4n for guile-user@m.gmane.org; Tue, 02 Jul 2013 23:32:05 +0200 Original-Received: from localhost ([::1]:55279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu8BA-0005ax-A4 for guile-user@m.gmane.org; Tue, 02 Jul 2013 17:32:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu8Ay-0005ac-6L for guile-user@gnu.org; Tue, 02 Jul 2013 17:31:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uu8Av-0003iL-Eh for guile-user@gnu.org; Tue, 02 Jul 2013 17:31:52 -0400 Original-Received: from mail-ea0-x232.google.com ([2a00:1450:4013:c01::232]:64080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu8Av-0003i5-9Y for guile-user@gnu.org; Tue, 02 Jul 2013 17:31:49 -0400 Original-Received: by mail-ea0-f178.google.com with SMTP id l15so3081325eak.9 for ; Tue, 02 Jul 2013 14:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=rXRK1I/7NhPutOsDBOL8+V+7hW4nR7p436cK8vQHogc=; b=EsRvBxiouHnvxaxu5OEnHNH8dk8kLwn/z/8yOfEcsyoICeEshPkfbE47a7cGb2z+N8 uErl8/m4U+V8cQsFFMsfbd5RJanODJQKvQdXcGkAZkN2YUcKX33kCCMMLbi3lbOxIouO pnpMmRpmUiGrXY94Dg633NLTB4Jtlxe/hImYqnVjICL3lZ/SLC4cNznOgZLl0spzGh4v Pm0NRV3yoTFDOrN837nQr3NCEBRLAk3P8NPjf3i9CK7L4EMVUbKRREweAj4ZEudIQQ/U 5nMjfJQyUEiXpzqoyeEdQxCRyXaD4tSwFhqUBvzZ4nIWomLj3vOhxTcGD9259h9LI5mv pS7w== X-Received: by 10.14.119.136 with SMTP id n8mr28217356eeh.1.1372800708255; Tue, 02 Jul 2013 14:31:48 -0700 (PDT) Original-Received: from honeybear.home (114.102-66-87.adsl-dyn.isp.belgacom.be. [87.66.102.114]) by mx.google.com with ESMTPSA id cg12sm39247480eeb.7.2013.07.02.14.31.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 02 Jul 2013 14:31:47 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::232 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10500 Archived-At: Hello, I'm playing around with interprocess communication through Unix Domain Sockets and guile. I've got 2 programs: a 'server' and a 'client'. I'm trying to send s-expressions from the one to the other using the 'read' and 'write' procedures. I've got the sockets set up currently: On the server:=20=20 (let ((s (socket PF_UNIX SOCK_STREAM 0)) (sock-addr (make-socket-address AF_UNIX "/path/to/socket"))) (setsockopt s SOL_SOCKET SO_REUSEADDR 1) (bind s sock-addr) (listen s 5) (let* ((client-connection (accept s)) (client-details (cdr client-connection)) (client (car client-connection))) (simple-format #t "Got new client connection:") (newline) (simple-format #t "writing message") (newline) (write 'test-comms client) (simple-format #t "Written. Now waiting for response.") (newline) (read) ; to make the server wait for standard input (close client))) On the client: (let* ((s (socket PF_UNIX SOCK_STREAM 0)) (path (string-append "/path/to/socket")) (address (make-socket-address AF_UNIX path))) (connect s address) (display (read s)) (close s)) - I first run the server, which sits and wait for client connections. - I run the client, which connects to the server - The server accepts, writes a message to client=20 - Then it moves on to the (read) stage - The client now simply reads from s in perpetuity When I finally provide some input and a newline in std input for the server, it closes the connection to the client, and at this stage the client finally returns with its reading from the socket. My question is simply: is this supposed to happen? Would I somehow need to close and re-open the socket to have a two-way conversation between the client and the server (e.g. client writes request, closes the socket, server reads from socket, evaluates, client re-connects, server provides response)? The documentation suggests that read simply reads one s-expression and returns (guile 2 > API > REPL > Scheme Read): Read an s-expression from the input port PORT, or from the current input port if PORT is not specified. Any whitespace before the next token is discarded. When I write several s-expressions to the unix port and then disconnect, the client does indeed read one s-expression at a time. Any ideas or comments as to what is going on? Best wishes, Alex PS: just noticed that changing the client socket from SOCK_STREAM to SOCK_DGRAM allows the client to read all but the final s-expression from the socket =E2=80=94 so it hangs on the last one. Again, closing the socket server-side then returns the last s-expression client-side. This wouldn't resolve the 2 way communications issue as SOCK_DGRAM does not seem to work for a server: (listen) returns an error with SOCK_DGRAM server-side.=20