Archived

This topic is now archived and is closed to further replies.

DirectXXX

Unexpected results in winsock

Recommended Posts

im a beginer. i followed some tutorials for AsyncSocks and non-blocking socks. i can easily send and receive simple characters(char*). but now i want to send X and Y position(intergers) values of my objects per 2seconds. i send the positions (ranges 0 to 800). but client only get value around 50.

Share this post


Link to post
Share on other sites
You should post more informations HOW you send them (a code snippet).
you don''t send chars but BYTES so it should work the same way, although you still have to keep in mind to reconvert the bytes to integers and that the integers you sent can arrive spilt up to several packtets.

Share this post


Link to post
Share on other sites
ok im telling more

as i said im using asocks for client and non-blocking server.

i want to send the mouse X any Y cordinates of window to other client when i click.

i am using this format

//mouse possitions
//xpos and ypos

char buffer[2];
buffer[0] = xpos;
buffer[1] = ypos;

send(server, buffer, sizeof(buffer));

the server just get that buffer from client1 and pass to client2. i have observed as value increases from 0 the receveing speed slows down. and it cant send position valuse greater than about 150.

Share this post


Link to post
Share on other sites
//mouse possitions
//xpos and ypos

char buffer[2];
buffer[0] = xpos;
buffer[1] = ypos;

I am assuming that xpos and yops are either shorts (16 bits wide) or integers (32 bits wide). You are assigning a char (8 bits wide or 0 -> 255) a larger value than it can hold. What happens in that case is that the higher order bits are truncated.

Not all types are equal. You need to read up a little more on your C.

quick and dirty solution

send(server, &xpos, sizeof(xpos));
send(server, &ypos, sizeof(ypos));

Share this post


Link to post
Share on other sites
DeltaVee already said why it didn''t work :S.
You either have to copy the integer to a buffer (sprintf()) or you have to send the integers like that:
send(server, &xpos, sizeof(xpos));
send(server, &ypos, sizeof(ypos));

the server has to receive them the same way, but in most cases, the xpos or ypos will be sent in multiple packts and won''t arrive at once, so you''ll have to read into a buffer and convert it to an integer whenever you got 4 bytes (4bytes=integer??).

You should better read a few more tuts about winsock, you can find some here on GDnet.

Share this post


Link to post
Share on other sites
really thanx for that. I am sorry i did not pay attention on data types and type casting when i was learning C. because it was looking boring stuff. Now i have realized how much important these boring things are. thanx again.

I did not found any wsocks resources which can tell theory. I dont know what happens to my data when i send it. Thats why im planing to buy a book. And can you tell me a web site which has good theory and explanation of wsocks to begginer instead of just do_this-do_this tutorials.

Share this post


Link to post
Share on other sites