🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

IMPORTANT WINSOCK QUESTION PLEASE RESPOND ASAP!!

Started by
21 comments, last by kalldrex 23 years, 3 months ago
quote: Original post by bit64

I might not fully understand your problem but what I think you are asking is how do you differentiate between messages. I would suggest to you that you learn DirectPlay SDK, if you program for windows, but here''s my suggestion.

get it?? I hope that answers your question, or else Ive typed a lot for nought. =)

Edited by - bit64 on March 6, 2001 11:50:57 PM


EXACTLY SOMEONE GETS WHAT I''M TALKING ABOUT! Thank you bit but unfortunatly i''m using winsock. I need to know how to tell the difference between incoming messages and have the server be able to tell what message is for what!

Advertisement
What you can do, is make the first byte (or maybe 2 bytes if you plan to have a ton of messages) be a special code that says what "type" the packet is. I'm gonna pull some random examples out now, you can of course use whatever numbers you want.

    unsigned char message[20];#define WALKPACKET 0x01#define TALKPACKET 0x02#define UPDATEPOSITION 0x03// Now if you want to send a talk packet, for example, do something likemessage[0]=TALKPACKET;strcpy(&message[1],"I am saying this stuff");// then put the winsock send commandsend(message,some other stuff, you know the drill);now, on the server end, it gets this packet, and you can do something like thisrecv(message, some other crap, etc);switch(message[0]){  case WALKPACKET:     // They sent us a packet whose first byte was 0x01, do something approproate  break;  case TALKPACKET:    cout << "They said " << &message[1] << endl;    break;  case UPDATEPOSITION:   // do something   break;  default:    cout << "Error, unknown packet!" << endl;}  


Do you get the idea? Rather than waste a ton of space sending "password=adjojd" you just send one byte that is "code" for "password=". It is still excess bandwidth, but honestly, who gives a crap about one byte?

Did that answer your question?

(Edit: the formatting was totally wierd, I tried to fix it)
Anthracks

Edited by - Anthracks on March 7, 2001 2:23:49 PM
Hi
I think i understand what ure on about if i get this completly wrong heh, sorry just ignore my message.

Basically i use a binary code, which is 1 byte, then i send something like "0x01" then i do a switch message and case to see the differnt messages ok enough of my dribble heres some code:

SERVER:

Firstly you check if youre recieveing a message(im not telling you how to do that as thats not what ure asking for), then you determine what message it is:

char buffer[1]; // To Store the Incoming packet message of 1 byte

recv(ClientSocket,buffer,1,0); // Then We receieve whatever data is coming from the client and store in our buffer<br><br>switch (buffer[0]) // basically saying if ( buffer[0] == ? )<br>{<br>case 0x01:<br>Disconnect(); // Received Quit Message<br>break;<br>}<br><br>Ok simple No?<br>the Client side<br>you create packet buffer:<br>char packet1[1];<br><br>packet1[0] = 0x01; // Put the Packet in the Packet buffer<br>send(ConnectionSocket, packet1, 1, 0); // Send the Packet to Server<br><br>Ok See Not so hard<br><br>Now of course if you were doing chat and such, you would need to send bigger data, but although i havnt done this, i would first send a Packet 0x02 as saying incoming chat message then send the actual chat message to server<br><br>Ok if im completly off the mark on what you wanted i really am sorry<img src="smile.gif" width=15 height=15 align=middle><br><br>Look out for my tut on Non Blocking Servers in Winsock (when i get around to it)<br><br><br><br><br>
Gachuk
Exactly right. Took me awhile to figure it out myself.

If you havn''t signed up yet for testing out Tombstone: Vendetta you can do so through my site. I''m working on some little things right now and should have the download available in a day or two.

Ben
http://therabbithole.redback.inficad.com
Yup. What you need to do is develop a protocol for the programs to talk to one another. ie. some set of symbols denoting what''s what, what data should be sent when, etc. Unless you decide to use XML (which is cool but way too bandwidth-intensive for gaming) expect to use a single byte to denote a specific operation or as a label for the type of data. So:
1=password
2=username
3=etc...
It another idea more flexible than juste set 2 bytes for definitions commands

is like IRC protocol.

use seperate character like

'':'' for seperate commands and text
''#'' for end of packet

make packet like

commands:text:other things#
can now have size U like!!
2char:20char#
1char:5char:5char#

-----------
XaK
That''s not needed.

Ben
http://therabbithole.redback.inficad.com
I think i''ll use the 0x02 or whatever cause i was thinking i shouldn''t need more then 99 different things, yet lol but yeah thanks!
ALL YOUR BASE ARE BELONG TO US!!!!
quote: i shouldn''t need more then 99 different things


Actually... you can get 256 (0xFF) out of the one byte
What was the famous quote? 64k should be... ahh well, have fun


Later,

Dak
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
so i can go up to 0x256 and ti will still be just one byte?
ALL YOUR BASE ARE BELONG TO US!!!!

This topic is closed to new replies.

Advertisement