Pages

Friday, November 18, 2011

On TCP & UDP, aka Networking

Over the past week, I have been hard at work getting a working protocol system implemented. As of today I am capable of updating the client with player coordinates and sending and receiving text messages. At first i began with a basic chat client server set up. The server spawned a new thread every time a client connected to it. Before i moved on to implement it into the game the chat server would only receive messages, not echo them to other clients.

Now i have moved on to a dual network stream per client structure. After extensive remodeling to my current set up of the game, i decided to cut my losses and create one simple library to be shared between both the server and the client. That way i could reference my classes without having to copy them over and worry about dependencies. Previously I had a rather strange system of inheritance.

A class, as in RPG class, not programming class. Say for example, a mage class. The class mage inherited an interface and a super class containing only variables. After reexamining C#'s inheritance system, my super class now inherits the interface and mage inherits the super class. However, one could remove the interface entirely and only use a super class, but that would take a little more time and possibly bug fixes.

The problem i am currently facing, is with my library, i designed most of the classes to be server side, thus they are essentially backwards on the client side.

EG: The server waits for a connection, so the client is supposed to be the one actively seeking the connection. Yet my current system has both client and server waiting at first. Problem? I think so, no connection would ever be made.

So that's where i am. Oh, and I'm also attempting to send the world data (its size and client.player id) to the client instead of it loading from the client's computer.

A quick note about UDP vs TCP. (I think it's important to know the difference)

first: UDP and TCP are both internet data relay protocols. UDP is built for speed while TCP is built for dependibility.

UDP says:
Server: HERE! THIS IS DATA! TAKE MORE DATA! HAVE ALL THE DATA!
Client: .......

TCP says:
Server: Here my good sir, have a little bit of data.
Client: Why thank you, this looks like x data.
Server: Why yes it is.
Client: Cool, thanks.

So as one can see, TCP involves more communication, but will make sure your data gets to the right place, while UDP just spits data out and doesn't have any client to server communication.

Personally, i'd use UDP for less crucial tasks, like updating a player's money, or their items in inventory. But for stuff like, player position or health, it would be good to use TCP.

If you have any questions, just ask!

TNariksan

No comments:

Post a Comment