Python, Windows, and file sockets

culix dndculix at gmail.com
Thu Oct 14 08:24:03 CEST 2010


Hey list,

I have a question about unix-style file sockets and/or named pipes
with python. I have a linux server program that uses a file socket to
listen for connections. It has been ported to Windows with cygwin (I'm
running WinXP SP3). On linux I have a python script that acts as a
client - it connects to the socket with code like

    sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
    sock.connect("/some/file/socket")

It then communicates with a bunch of sock.send() and sock.recv() calls
as normal.

Since the server runs on Windows I would like to make the client run
on Windows. However, this seems to be difficult because the AF_UNIX
socket type has not been defined in Windows python. I have tried using
'multiprocessing' Pipes and Clients, as well as the 'socket' module,
but in both cases I get an error that says "'module' object has no
attribute 'AF_UNIX'". As well the socket documentation says "If the
AF_UNIX constant is not defined then this protocol is unsupported" (
http://docs.python.org/library/socket.html#socket.AF_UNIX ). I also
tried using select(). For select.select() the docs say "On Windows,
the underlying select() function is provided by the WinSock library,
and does not handle file descriptors that don’t originate from
WinSock". Indeed, if I try this (after opening the socket with
subprocess.Popen()), I get "'C:\some\file\socket' is not recognized as
an internal or external command, operable program or batch file" on
the command line, and "<class 'select.error'> (10038, 'An operation
was attempted on something that is not a socket')" from python.


I have successfully written C code that will talk to the file socket
on Windows, so I believe this is possible on the OS. But I would
rather port the existing python client than create a new one in a
different language.

So: is it possible to talk to a file socket via python on Windows?
Does it require implementing enough functionality to get AF_UNIX
sockets defined? Is there some other obvious method that I'm
overlooking?


Thanks for listening,
culix



More information about the Python-list mailing list