First off... for something like this, I wouldn't use UDP, I would use TCP/IP. There's really no reason to use UDP, which sends datagrams with no built-in error checking, TCP/IP already handles the error checking/handling (i.e. it'll automatically retransmit packets that didn't arrive at their destination correctly). Usually you only want to use UDP when you have something that doesn't require reliability like voice or video (i.e. if you lose a packet here and there it won't really matter, you'll still be able to hear/see the other person).
As far as sending the data, if you're making for the server and client, it's easy, you define the data messages/structures that are being passed between both completely yourself (via what is typically referred to as an API). Usually the packets are made up of binary buffers, within that buffer, you can either have fixed length or variable length data buffers (or packets), the structure of which is completely up to you.
For example, you can specify:
0. first 4-bytes of the buffer define the message type
1. next 4-bytes define a message specification
2. next 4-bytes define the message size
3. so on...
In this scenario, when you receive a packet, first thing you'll do is cast it onto a data structure that is defined by your API. The first portion of the structure would be an int type (picked it because it's 4-bytes in a 32bit system) and it can specify the type of message that is contained in that data packet. The next portion can be a subset of that message and so on.
Search google and CodeProject for client/server examples and see how they defined their messages.
Last Visit: 31-Dec-99 18:00 Last Update: 9-Mar-14 9:22