Unix domain socket in python example?
Grant Edwards
grante at visi.com
Sun Oct 28 00:24:11 EDT 2007
On 2007-10-28, wsguglielmetti at gmail.com <wsguglielmetti at gmail.com> wrote:
> Can someone please point me to some resource in the internet
> that have a code like that one in a fashion that I can adapt
> it?
http://docs.python.org/lib/socket-example.html
It's trivial to change it from INET to UNIX domain.
> Or maybe post a example code here in the forum..
# Echo server program
import socket,os
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
os.remove("/tmp/socketname")
except OSError:
pass
s.bind("/tmp/socketname")
s.listen(1)
conn, addr = s.accept()
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
# Echo client program
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/tmp/socketname")
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)
--
Grant Edwards grante Yow! Look!! Karl Malden!
at
visi.com
More information about the Python-list
mailing list