467,161 Members | 868 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Unix domain socket in python example?

Hi,

How are you?

I'm completly new in python but I know a little of C.

I developed a small application in python which generate and receive
some data from times in times (question of seconds) and I need to send
this data to a unix domain socket (/var/run/sfp) and read the
response and print on the screen.

I looked for a example of source code in python which connect to a
unix doman socket, send some data and print the response on the
screen, however I were unable to find it.

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? Or maybe post a
example code here in the forum..

Thank you,

Cheers

Oct 28 '07 #1
  • viewed: 12218
Share:
1 Reply
On 2007-10-28, ws************@gmail.com <ws************@gmail.comwrote:
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
Oct 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by RosalieM | last post: by
1 post views Thread by Didatus | last post: by
1 post views Thread by Chris | last post: by
4 posts views Thread by Kris Kennaway | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.