"Which one''s easier?"
Neither because you have no clue what you''re doing.
"since sending side doesn''t know how many places it takes up"
Well that''s stupid. Why doesn''t either side know how much is comming in?
If neither side knows what''s comming in then you''re missing the most critical part of a networking protocol (which is what you''re creating); a header. You can''t just blindly send off packets without a fixed number of bytes at the beginning telling the other side how to interpret the information.
You need to sit down and plan out how you''re going to implement your protocol. Look at the source for Gang Wars and my Winsock Class. Both have a different protocol but use the same concepts in creating it.
If you don''t realize the importance of converting everything to bytes or that char [] is not a string (it''s a series of base 256 values which an int takes 4 of) then networking is going to be way over your head. You''d be better off learning how to write and read binary files because it''s the same concepts but without the overhead of learning Winsock as well.
Ben
IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Dot Com | GameShot ]
Sending Integers
OK I''m just using
send(socket, (char *)&Player1.xpos, ...);
recv(socket, (char *)&Player1.xpos, ...);
but when the game tries to send to the server, I get an illegal operation warning and I have to close the server program.
send(socket, (char *)&Player1.xpos, ...);
recv(socket, (char *)&Player1.xpos, ...);
but when the game tries to send to the server, I get an illegal operation warning and I have to close the server program.
quote:
Original post by Anonymous Poster
Now perhaps you all get that''s it''s not so silly to send a string containing the integer, and then convert it....
Much easier.
quote:
Original post by BioSquirrel
Sending a message works but the integers are really confusing. Can someone explain to me why it''s so much harder to send an integer?
It''s not harder. It just requires a few minutes'' more reading. If people just take the time to look up htonl() and ntohl() then everything is plain and simple.
As for your illegal operation, that is probably because you''re not reading it properly. You should use a debugger to find out exactly what the issue is, because your server shouldn''t crash just because it got sent an invalid number.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
quote:
Original post by Anonymous Poster
Now perhaps you all get that's it's not so silly to send a string containing the integer, and then convert it....
Much easier.
So what if the number is 400000 ? "400000" = 6 bytes plus zero terimnation. 7 bytes. An int is 4 bytes.
Of course if the number was 2 you would have saved 2 bytes. By the way. That endian thing is only relevant if you plan to cross platform your game.
[edited by - granat on October 5, 2002 1:28:36 PM]
-------------Ban KalvinB !
I think AP was refering to converting an int to a base 256 string as in char [] which is something the OP has been arguing against.
Not sending it as a base 10 string which no one has ever even suggested.
"send(socket, (char *)&Player1.xpos, ...);"
How many bytes are you sending? If .xpos is an int then "..." should be exactly 4.
Ben
IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Dot Com | GameShot ]
Not sending it as a base 10 string which no one has ever even suggested.
"send(socket, (char *)&Player1.xpos, ...);"
How many bytes are you sending? If .xpos is an int then "..." should be exactly 4.
Ben
IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Dot Com | GameShot ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement