transmit an array via socket
Collapse
This topic is closed.
X
X
-
Jeff PangTags: None -
Diez B. Roggisch
Re: transmit an array via socket
Jeff Pang schrieb:Using XMLRPC or Pyro or other RPC mechanisms instead of reinventing aI want to transmit an array via socket from a host to another.
How to do it? thank you.
wheel that is larger than the socket API suggests in the first place.
Diez
-
7stud
Re: transmit an array via socket
On Oct 26, 11:52 pm, "Jeff Pang" <pa...@juno.com wrote:Try this:I want to transmit an array via socket from a host to another.
How to do it? thank you.
>
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(1 012)
data_list.appen d(partial_data)
if not partial_data: #then got all the data
break
data_str = ''.join(data_li st)[:-1] #chop off trailing comma
arr_strs = data_str.split( ",")
arr_ints = [int(elmt) for elmt in arr_strs]
print arr_ints
Comment
Comment