473,287 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 11129
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 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.