Game Programming III Week Two: Network programming
|
I haven’t really done anything on my personal projects (or assignments) this week, therefore I feel that the only thing I can write about is what we did on the lectures: an introduction to network programming using sockets. For the uninitiated, sockets can be somewhat likened to electrical plugs. You decide on a port where you send or receive data, similar to choosing one specific outlet to plug in whatever electrical appliance you might have. You then create a socket and bind it to the port (plugging in the plug in that specific outlet), which allows you to send or receive data (electrical current, though you probably shouldn’t send electrical current into an outlet) until you close the socket (pulling the plug). As for the transferring of data, this is most commonly done using the TCP and UDP-protocols. The difference between these two are many, but the major differences is that TCP requires a connection to be established between two computers before it starts sending data. It also orders and error-checks the packets (which causes it to be very reliable, since you either get the full packet, or you don’t get it at all). UDP on the other hand just sends data everywhere without any guarantee of the data arriving, and if it does, there’s no guarantee that the packets are complete, without errors or even in the right order. However, thanks to this, UDP has a lower performance cost than TCP. In order to familiarize ourselves with those two protocols, we created a simple chat client using UDP during the lectures, and got an assignment to create a web server using TCP. The reasons for using UDP in the chat program is that the sheer speed of UDP and way lower overhead cost outweighs the reliability of TCP for a chat program. Even if you miss a packet here and there, it’s not the end of the world. As for the web server, one of the biggest reasons for using TCP is that since UDP has no error checking, we could end up with dropped packets or packets arriving in the wrong order, which would then cause the web page to end up being broken and force the browser to send requests to the server until we get every packet. Using TCP allows us to send all our packets once, and then letting the protocol itself handle resending if needs be. I haven’t started on the second assignment, but I should probably do that some time soon…
|