Link to home
Start Free TrialLog in
Avatar of James Hancock
James HancockFlag for United States of America

asked on

Python - creating byte arrays help

Hi

I have my TCP connection, server listen code fleshed out.
On the client, though,
I'd like to create a byte array of a certain length, with a tag number.
How do I do this?
basically Java,

byte[] data = new byte[500] // is that the correct size for a TCP network game HELO message? smaller? can be 3 . . .
data[0] = HELO_MSG byte
data[1] = client number byte #1
data[2] = client number byte #2
That's all? no need for more than 256 clients..so, one byte.
The client port, address, etc is gathered from this message.
I can send and listen, but I don't know how to create a blank byte[] of x size and fill it with certain numbers?
byte[] data = new byte[3]
What about in game messages, that can be hundreds of bytes?
Avatar of James Hancock
James Hancock
Flag of United States of America image

ASKER

I found this, that worked over TCP.
s.sendall(b'Hello, world')

Open in new window


Is that right? It didn't explode.
How do I make a bigger byte array for in-game messages? Or are they not big. I'm thinking big because of movements of large numbers of units. Must I keep groupings of units registered in the server?
How can I set the size of each type of message byte array?
Incidentally, when I hardcoded the byte array, my other socket explosions stopped.
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks

bytearray is the answer

am doing

data=bytearray(5)
data[0]= MSG_HELO

and it sends this over TCP the same.