Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Unix domain socket in python example?

Reply
Thread Tools

Unix domain socket in python example?

 
 
wsguglielmetti@gmail.com
Guest
Posts: n/a
 
      10-28-2007
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

 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      10-28-2007
On 2007-10-28, <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_fcgid: couldn't bind unix domain socket Gambito Ruby 0 09-10-2008 10:07 PM
Unix domain socket (AF_UNIX) support for Java sockets Chris Markle Java 0 04-24-2004 12:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57