Programming 3 second week.

This is the second blog post of programming 3. What I am going to talk about today is about networking, mainly about receiving packages from peers. Throughout the week the class has been creating a simple (not that simple) chat program. To start with you have to activate WSA data and then sockets in order to start networking. When receiving packages the program must also determine what to do with the package and peers. Therefore a basic networking program requires certain elements to maintain the network. Just receiving data is one thing but we must also know when a user has disconnected and we also need to maintain the connection between the peers. To do that we check with every package that is received if the sender is in our peer list and if not the new peer will be placed in the peer list. To check if the player has disconnected the program must check the connection every now and then (in this case every tenth second) and if the connection is dropped the peer will be removed from the list.

The most interesting part of this program was how we first thought that we only could scan and take pieces of the package received to us. But what we didn’t know was that the UDP network does not work that way, by just taking a small piece we got the socket error 10040 which means that the package is larger than the buffer we created. At first we only took as much data as the message was; sizeof(). But in order to make it work we had to set up a buffer that could handle the package. To give the package more than enough space the buffer was changed to 4096. But the question is how a larger scale program handles the chat messages when the text is really long, I know some programs limits the amount of signs but some don’t, there’s gotta be a way to make the buffer dynamic.