WinSuck, can only send a char* ?
Oh yes, lets all start insulting API''s as a method to get people to write code in them for us.
-~-The Cow of Darkness-~-
just to say dont use JonStelly struct solution, diferent arquitectures/compilers/OS can compile structs diferently.
Besides if you put and int and a char in a struct it will take 8 bytes (assuming x86), so you would be sending 3 byes of garbage
Besides if you put and int and a char in a struct it will take 8 bytes (assuming x86), so you would be sending 3 byes of garbage
To be considered a genius you just have to say what everybody knows in a way very few understand
i got trouble again.. [img]http://musik4you.i-networx.de/zuzuzu.PNG[/img]
what you think about it ?
what you think about it ?
first you talk abou send now you talk about opengl!?
for that you must uso itoa look it up.
for that you must uso itoa look it up.
To be considered a genius you just have to say what everybody knows in a way very few understand
quote:
Original post by Wickeeed
i got trouble again.. [img]http://musik4you.i-networx.de/zuzuzu.PNG[/img]
what you think about it ?
i should laught, but i will try to explain it
![](wink.gif)
ok lets start with this: a pointer is an address into your memory. when you cast a pointer to memory of a different type, it will only change the pointer pointing adress, not the content of the memory! so your pointer is pointing to the memory of an int. now you can try handle the adress where the pointer points as the type the pointer should point (this will not change the content of the memory!) so in your example your pointer is pointing to a byte containing 123, followed by 3 remaining byte of the 4byte int (if your int isnt 4 byte think different) containing the remaining part of the int, if your computer is using the motorola-order you will have the bytes reversed (not on intel/amd cpus!). Now you try to print the content of the memory pointed by your pointer, this contains 123 or as a char the symbol you see! if you want to display the transfered int you will have to redo the cast with code like:
int yourint;
yourint= *((int*)pointer);
remember: a pointer isnt necessary pointing to data in the format the pointer points to...
but you should read a bit about pointers and this sort of stuff before making überleet network-games
![](wink.gif)
T2k
i only need to send() Coordinate from Player to server, but how i can do that ?? with char ?? and without books ??!
quote:
Original post by T2kquote:
Original post by Wickeeed
i got trouble again.. [img]http://musik4you.i-networx.de/zuzuzu.PNG[/img]
what you think about it ?
i should laught, but i will try to explain it
ok lets start with this: a pointer is an address into your memory. when you cast a pointer to memory of a different type, it will only change the pointer pointing adress, not the content of the memory! so your pointer is pointing to the memory of an int. now you can try handle the adress where the pointer points as the type the pointer should point (this will not change the content of the memory!) so in your example your pointer is pointing to a byte containing 123, followed by 3 remaining byte of the 4byte int (if your int isnt 4 byte think different) containing the remaining part of the int, if your computer is using the motorola-order you will have the bytes reversed (not on intel/amd cpus!). Now you try to print the content of the memory pointed by your pointer, this contains 123 or as a char the symbol you see! if you want to display the transfered int you will have to redo the cast with code like:
int yourint;
yourint= *((int*)pointer);
remember: a pointer isnt necessary pointing to data in the format the pointer points to...
but you should read a bit about pointers and this sort of stuff before making überleet network-games
T2k
very nice THX T2k ,, i think i got it
![](smile.gif)
quote:
Original post by luxitan
just to say dont use JonStelly struct solution, diferent arquitectures/compilers/OS can compile structs diferently.
Besides if you put and int and a char in a struct it will take 8 bytes (assuming x86), so you would be sending 3 byes of garbage
Point 1) If we''re only talking about windows and you use the same compiler / settings to build both server and client binaries, it doesn''t matter. If we''re talking about cross-platform then I''ll assume GCC for *nix and MSVC or DJGPP for Windows. All of them have the same basic layout for a structure, ignoring type size differences, and assuming you process the message by converting multibyte integers to network byte-order before sending and to host byte-order after receiving.
Point 2) #pragma pack(1) prevents wasted space in structures between members. It''s supported on MSVC and any recent version of GCC.
September 12, 2003 04:47 PM
This is one problem with so called "computer studies" classes these days. They teach C++ and Java without using the concept of pointers to memory like you had to use in C.
*sigh*
*sigh*
It''s not a Winsock problem. It''s a "I don''t have any idea how to code but I heard MMOs were ''cool'' so I want to do one, too!" problem.
On a network everything is broken into bytes and sent out on the wire. A magical thing called a "header" tells the other side how many bytes make up the message and how to interpret the data.
If you actually knew anything about coding you''d realize that getting data onto a network is exactly the same as saving and loading a binary file.
You add 8 because the message length is the number of data bytes. The header is 2 additional ints which is 8 bytes.
Ben
.action has a dream that one day clueless newbies will stop claiming the nail is broken simply because they can''t figure out how to use a hammer.
[ IcarusIndie.com | recycledrussianbrides.com ]
On a network everything is broken into bytes and sent out on the wire. A magical thing called a "header" tells the other side how many bytes make up the message and how to interpret the data.
If you actually knew anything about coding you''d realize that getting data onto a network is exactly the same as saving and loading a binary file.
struct message{int type;int length;char data[65536]; //64K is overkill};struct message_type1{float xpos;float ypos;float zpos;};message msg;message_type1 position;msg.type=1;msg.length=sizeof(message_type1);position.xpos=3.56;position.ypos=-3.1;position.zpos=2.1;memcopy(&msg.data,&position,msg.length);send(msg,msg.length+8);
You add 8 because the message length is the number of data bytes. The header is 2 additional ints which is 8 bytes.
Ben
.action has a dream that one day clueless newbies will stop claiming the nail is broken simply because they can''t figure out how to use a hammer.
[ IcarusIndie.com | recycledrussianbrides.com ]
![Will Post For Food](https://www.paypal.com/images/x-click-but21.gif)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement