Friday, April 30, 2010



Chapter 3: Client

[Prev: Server] [Next: Telling the Server]


base.gmk object obj_dll create event
server = tcpconnect("43.39.9.132", 12000, 2);
if (server < 0) game_end();

This makes the program send out a connection request to the computer at IP 43.39.9.132, you will need to change this to the server's IP address (if you are on the same network, the network card will contain the IP address, otherwise use "whatsmyip.org" to get it). The next number is the port, notice it is the same as the server's "tcplisten" command in the previous chapter, these must be equal in order to make a connection. The last number means we don't want the connection to freeze our program, so just set it to "2" (some computers may require it to be "1" which is also a nonblocking connection, but only after the primary data send -- this isn't anything to worry about, if "2" doesn't work, use "1" that simple). It will return the socket for the connection or "-1" if it fails. Save this as client.gmk. You can effectively run both the server.gmk and the client.gmk (in that order) and create a connection between the two (use "127.0.0.1" for IP to connect to yourself). Right now there is nothing fancy, it just creates the connection. Let's put some movement into our character.

client.gmk object obj_player step event
if keyboard_check(vk_up) y -= 1;
if keyboard_check(vk_down) y += 1;
if keyboard_check(vk_left) x -= 1;
if keyboard_check(vk_right) x += 1;

This is a basic moving object, you can use any image you want and put 1 in the first room of the file.


[Prev: Server] [Next: Telling the Server]



Chapter 1: Requirements

[Prev: None] [Next: Server]


This document follows the creation of programming a multiplayer connection using Game Maker 7. Following that, you will need:
For the 39dll.dll, the link provided is to the topic itself on GMC. It contains the file suite (which contains a small tutorial, gm files, like the Dllscripts.gm6, and the 39dll.dll). If you would like to dive right in and read the tutorial provided, by all means, you can come back here if you get stumped. The file I have provided in this tutorial contains the 39dll.dll file, if 39ster has a problem, I will have to remove it.

This tutorial contains a build-up of 2 separate programs. If you do not feel like following through the tutorial, you can find the full list here on host-a.net. The programs are labeled based on the old chapter numbers.


[Prev: None] [Next: Server]

Thursday, April 29, 2010



Chapter 2: Server

[Prev: Requirements] [Next: Client]


No matter what networking game it is (RTS, FPS, RPG, etc.), in order for it to work on a network, there must be at least 1 computer as the server. When making a call on the phone, someone must be on the other side to pick up -- the same thing for the internet. Do not think of a server as this highly powerful untouchable thing, it isn't. The main job of a server is to "listen to the phone" waiting for people to connect to it, and transfer data between people.

Imagine a local bar, does the waitress go door to door selling liquor? No, this is similar to what a server does, the client must walk "into the bar" (connect) to get liquor, and it also allows people to see each other. This is just a crude analogy.

Let's go ahead and start making some code. We will begin with initialization, like most things, variables need to be set properly before they are used, 39dll is no different. Start by loading the Dllscripts.gm6 file, create a persistent object called "obj_dll", and in the create event put:
dllinit(0, true, false);

The first argument "0" means use "39dll.dll" file, if you rename the dll file, you would put the string here. The second argument loads our network functions, the third loads utility functions (which we won't use in this tutorial). You only need to place 1 of these objects in the first room and you're done. Save this file as base.gmk because we will be modifying it further as we go through the other chapters.

*note: From here on I will be mentioning code and in what module to add it to with a short description to make learning quicker. If more information is needed, I will put it.

base.gmk object obj_dll create event
listen = tcplisten(12000, 4, 1);
if (listen < 0) game_end();

This makes the program begin listening to port 12000. When the server is busy, it can not always connect people right away, this is called a queue, and the "4" is how many in that queue are allowed. If the queue is full, any new clients will be ignored, 4 is sufficient for now. The "1" means "non-blocking", it deals with parallelism, which is what we want, so just set it. The function returns a "socket" required by other functions or "-1" if it failed (a socket is the connection between your program and the network card containing information about the virtual connection between the two computers, the complex actions are seemlessly done by the simple functions supplied by 39dll). We need an object to hold client connections, so create persistent object "obj_client".

obj_client create event
client = -1;

obj_dll step event
client = tcpaccept(listen, 1);
if (client >= 0)
{
    o = instance_create(0, 0, obj_client);
    o.client = client;
}

When clients try to connect, the server must accept their connection (which means the underlying socket will store their IP and port information for you). It will grab the first in the queue and create a connection and return the socket (or "-1" if none were in the queue). After a connection has been made, we create the client object and give it the socket. Save this file as server.gmk.


[Prev: Requirements] [Next: Client]

Network Coding (Intro)

I've decided to start right in with my coding blog in programming network communications. This will be tough going as I move my documents over, but please bare with me.

To start off with, this particular thread will contain the links to the different chapters, and each chapter will link to previous and next chapters. This will centralize most of my work and allow me to just link to this file for convenience.

Ok, here we go.

Chapter 1: Requirements
Chapter 2: Server
Chapter 3: Client
Chapter 4: Telling the Server
Chapter 5: Relaying to other Clients
Chapter 6: Clients Understanding
Chapter 7: ID the Clients
Chapter 8: Disconnecting

Possible Additions later
Chapter ?: Passwords and Authentications
Chapter ?: Database
Chapter ?: Signing Up and Logging In
Chapter ?: Patch Database
Chapter ?: Node Mesh
Chapter ?: Sync Updates
Chapter ?: Throttling
Chapter ?: Dead Reckoning
Chapter ?: UDP, the Good and the Bad
Chapter ?: Reliable UDP