473,387 Members | 1,575 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,387 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 11145
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.