472,988 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 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 11029
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jeevan | last post by:
Hi, I have some data which I am getting from a socket. I am currently storing the data in an array (so that future reading of the data will be fast as it will be in RAM instead of hard disk)....
1
by: user | last post by:
Hello I have a thread1 in which i am in infinite loop reading data from socket. But sometimes i want to transmit data using that socket (thread2 decides about it). Can i simply from thread2 call:...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
2
by: Ron | last post by:
Hello, I am trying to read a list of files from an FTP server (mainframe) to a byte array using sockets as follows, but not getting all the files in a given directory: private readonly static...
1
by: Dave | last post by:
How could I create a socket array? Such as if tSocket was a socket then, tSocket(1); tSocket(2);
2
by: Shreddy | last post by:
Hi, I'm trying (or struggling) to convert some C code to C#. The existing C client is sending a structure via a TCP socket to a network server. The structure contains a mix of int and char...
3
by: Fireangel | last post by:
I want to cast a class into a byte array. I've seen some examples of this floating around, but they all have simple data members. What happens if I cast something that has a ArrayList or an...
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
4
by: setiarakesh | last post by:
I have designed a socket Server and developed asynchronous server . It is working fine with 60 Clients which are connecting to ths Server running at Machine (2 GB RAM and OS is Windows 2003...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.