Writing Net Code vs Using a Library

Started by
1 comment, last by graveyard filla 19 years, 2 months ago
I was beginning to write the net code for a game me and a few others are working on. I was planning on using C sockets, I have a bit of experience. It seems to me that writing the code to actually send the packets isn't that difficult. On the other hand, programming the system to know how to use the data that you receive is where the challenge is. My question is, what is it that Net Code Libraries do that make them so helpful? Do they automatically format the packets for you such as if I wanted to send "Hello", it sends 05Hello and all you have to worry about is that you got "Hello" on both sides? Or do they provide some sort of support that is extremely helpful for game programming? Does it just provide a way to send data without worrying about handling reads and writes?
Advertisement
Well, I haven't tried another libraries, but I've done one. You only need to use a function to add an opcode (you tell the opcode number, and a function that will be called when it arrives). For example...

#define OP_TEST 0
void test(char* data,int32 size){
printf("Hey, %s arrived!",data);
}
void main(){
CofruNet* CN=new CofruNet(1); //1 opcode
CN->AddOpcode(OP_TEST,test);
CN->StartClient(someip,someport);
CN->StartReceive();
while(1){}
}

This is a client example, sure it containts functions for server. So when a packet of opcode OP_TEST arrives, it will decompress it(if compressed bool was true in the CN->Send function) and call the function 'test' with the data and size. It is really easy to use, most things are automatic. If you wanna test it, download the library from http://cofruben.krusher.org
networking libraries come in many different levels. at the lowest level (after win/bsd sockets), they are just light weight cross platform wrappers for sockets, so you dont have to write the cross platform code yourself (SDL_net). at a little higher level, they provide reliable UDP, packet sending / splitting, automatic connection management, ordering channels, etc. (eNet). at an even higher level, they could provide everything previously mentioned, plus encryption / authentication, compression, lobbying services, auto-patching, etc. (RakNet). check out the forum FAQ for a complete list of libraries.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement