Sign in to follow this  

Speeding-up socket communication

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

This topic is 4870 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this