Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock - Sending an Array

Status
Not open for further replies.

Hawkeye123456

Programmer
May 5, 2000
24
0
0
US
Is there any way to send an array over a winsock controll? I am writing a game that used a server to get map files from. The files are stored in an array. I need to send it to the client. I really hope that I can send the array, and not have to get all the data out of it then send, and recomplile it on the other side.
 
Thanks, but that did not help me out too much.

I need to pass a Variable array through the control.

Thanks though

--Joe
 
Hawkeye -

There's no way to send the array "as-is" through a socket. You will have to do it the hard way -- sorry!

What I recommend is you first send the number of elements in the array, then loop through the array sending each element.

If the array is of complex types (i.e. not just integers), you will have to make sure you and the other end agree exactly as to the layout of the data.

Note that sending floating-point numbers can be a problem, so you'll have to convert them to fixed-length strings before sending them. You can't just convert them to ordinary strings, since they would be of varying length and the other end wouldn't know how much data to receive.

Same applies to strings in general -- the other end has to know how much data to expect, so for each string, you'd have to either send the length in advance (as an integer!), or send only fixed-length strings.

Oh, and if the other end of the connection isn't running on an Intel CPU, you might have problems with big-endian vs. little-endian numbers. Intel CPUs store numbers in reversed format, and other CPUs store them the other direction. If this is the case, you'll have to send numbers as fixed-length text as well. This is the big problem that XML solves. But for a game, XML would be too wordy and would slow things down too much.

What you might want to do is examine some of the source code that id (Doom, etc) has released. There's some networking code in there somewhere. You'll see that they're doing all of the above, plus more to shrink the size of their network packets.

Hope this helps.
Chip H.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top