Jump to content
  • Advertisement
Sign in to follow this  
Demx

dynamic array through sockets

This topic is 2171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey,
as in title is it possible to send a dynamic array through sockets with WinSock2 ?

Share this post


Link to post
Share on other sites
Advertisement
Of course. You can send anything over a socket that can be encoded as a sequence of bytes.

Are you interested in a particular language's capabilities in this regard, or a networking library, or...?

Share this post


Link to post
Share on other sites

im interested in c++


C++ doesn't have any network features and winsock is a low level library so its all up to you how to encode and send it.

one rather simple format to encode an array in would be
a header that tells the reciever that the packet contains an array with x elements of datatype y. (in a verbose plaintext format you could encode it as Array:5454:Enemy (in a binary representation you'd replace the words Array and Enemy with an integer number between 0 and the max number of different packet and datatypes supported)
and then just send 5454 Enemy objects (if they have a fixed size you can just write the member variables in a fixed order to the socket, if they have dynamic fields you need a header for each object in the array aswell) Edited by SimonForsman

Share this post


Link to post
Share on other sites
One cannot answer this in isolation. It is intimately connected with how you construct valid outgoing "messages" and how you try interpret potentially valid incoming messages. Have you such a schema already? If so, what is it?

Are you using TCP or UDP?

Share this post


Link to post
Share on other sites
i'm using TCP

currintly im sending messages with structs

struct ClientPacket
{
Player p;
};


void Send()
{

ClientPacket packet;

packet.p = a;

send(conn,(char const *)&packet,sizeof(packet),0);

}

Share this post


Link to post
Share on other sites
Depending on how Player is defined that may not work. It would probably be better to use a marshalling/serialization library. Edited by wood_brian

Share this post


Link to post
Share on other sites
How would you save this array to a file? Sending data over TCP is very similar to saving (and re-loading) data to (and from) files.

Share this post


Link to post
Share on other sites
ok so is there any way to send a dynamic array in the struct i'm sending ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!