Jump to content
  • Advertisement
Sign in to follow this  
Floating

Speeding-up socket communication

This topic is 5087 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

Hi, I am very new to socket and such things and I might just have understood it wrong, but here is my problem: I wanna send some simple commands through sockets, however the simple commands are sometimes accompanied by heavy data. As far as I understood it socket communication consists in just sending/receiving strings. So this means the data will first have to be converted into some sort of "printable" data? I thought I can write: int data; char command[]="COMMANDxxxx" *((int*)command[7])=data; and then send the command string but this doesn't work! I will have to write something like: int data; char command[]="COMMANDxxxxxxxx" convert data to hex value and append after "COMMAND" But like that my data becomes twice as big. How do people usually do that? Thanks

Share this post


Link to post
Share on other sites
Advertisement
It depends on the socket interface you are using. There might be some that limit you to printable strings, but more likely you're doing something else wrong.
The most likely problem is that you're using "strlen" on a string that is not null terminated. You'll need to take the length before you write the int or calculate it some other way.

Share this post


Link to post
Share on other sites
Thank you Extrarius,

I looked a bit into it and there are also functions to send individual bytes, so there is no ptroblem :)

Share this post


Link to post
Share on other sites
The data doesn't need to be converted to a human-readable format to be sent over a socket. Sending the raw data should be enough.



Disclaimer:


Different systems store data in different ways, so when I say "raw data", I mean network-byte ordered packed data.

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!