how to transfer integer on socket?

F

Frank Potter

Is there any easy way to transfer 4 bit integer on socket?

I want to send like this:

a=5
send_integer(socket_s,a)

and receive like this:
a=receive_integer(socket_s)

Sending and receiving is in binary form, not transfer it to string.
Is there any easy way to do this?
 
G

Gabriel Genellina

Is there any easy way to transfer 4 bit integer on socket?

Extend it to 8 bits (1 byte) and use a single character (string of length
1)
I want to send like this:

a=5
send_integer(socket_s,a)
socket_s.send(chr(a))

and receive like this:
a=receive_integer(socket_s)

a = ord(socket_s.recv(1))
 
I

Irmen de Jong

Frank said:
Is there any easy way to transfer 4 bit integer on socket?

I think you mean a 4-byte integer?
Look at the struct module, anyway.

--Irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top