471,330 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

transmit an array via socket

I want to transmit an array via socket from a host to another.
How to do it? thank you.

--jeff
__________________________________________________ ___________
Largest network of startups. Find new startup opportunities. Click here.
http://thirdpartyoffers.juno.com/TGL...XJnlSuTKfzxO4/
Oct 27 '07 #1
2 10379
Jeff Pang schrieb:
I want to transmit an array via socket from a host to another.
How to do it? thank you.
Using XMLRPC or Pyro or other RPC mechanisms instead of reinventing a
wheel that is larger than the socket API suggests in the first place.

Diez
Oct 27 '07 #2
On Oct 26, 11:52 pm, "Jeff Pang" <pa...@juno.comwrote:
I want to transmit an array via socket from a host to another.
How to do it? thank you.
Try this:

client:
-------
import socket

s = socket.socket()
host = 'localhost'
port = 3030
s.connect( (host, port) )

arr = [1, 2, 3]

for elmt in arr:
send_str = "%s," % str(elmt)

while send_str:
chars_sent = s.send(send_str)
send_str = send_str[chars_sent:]

s.close()

server:
-------
import socket

s = socket.socket()

host = "localhost"
port = 3030
s.bind((host, port))

s.listen(5)

while("Ctrl-C hasn't been entered"):
new_sock, addr = s.accept()
data_list = []

while True:
partial_data = new_sock.recv(1012)
data_list.append(partial_data)
if not partial_data: #then got all the data
break

data_str = ''.join(data_list)[:-1] #chop off trailing comma
arr_strs = data_str.split(",")

arr_ints = [int(elmt) for elmt in arr_strs]
print arr_ints

Oct 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Jeevan | last post: by
6 posts views Thread by Ricardo Quintanilla | last post: by
2 posts views Thread by Ron | last post: by
1 post views Thread by Dave | last post: by
3 posts views Thread by Fireangel | last post: by
9 posts views Thread by Miro | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.