Cii Forum
Please login.

Join the forum, it's quick and easy

Cii Forum
Please login.
Cii Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

The forum for the program Cii (Wii PC).

I just created the forum. Please come back often and post!

You are not connected. Please login or register

On topic of coding.

2 posters

Go down  Message [Page 1 of 1]

1On topic of coding. Empty On topic of coding. Wed Aug 19, 2009 10:57 am

link3000

link3000
Cii Adept Gamer
Cii Adept Gamer

Continuing from my last topic, On Topic of Networking, I'll be going over the coding structure of networking.

Once again, we'll be using 39dll by 39ster. The download include the DLL, and example, and documentation.

For those not familiar with computer networking above the mplay level, connection is made to an IP or URL, whichever is playing the role of a server, and then connects to a port. When the connection is successful, data is then sent through sockets to the receiving end.

Basic Connection in 39DLL-

The first step is for the host to create a listening socket, which is used to check for clients trying to connect. In 39DLL, this is done through:
Code:
tcplisten(port,max,mode);
port - The port to listen on.
max - The maximum clients allowed on the wait list.
mode - Set to false to block, otherwise the socket is non-blocking.
That function returns the socket, if there was an error, it returns a negative error code, or 0.
Code:

listen=tcplisten(4444,100,1);
if (listen<=0) {
    show_message("Error: "+string(listen));
    game_end();
}
This code creates a socket listener on port 4444 with a maximum of 100 clients on the wait list, with the mode set to non-blocking.

The next step is for the host to accept incoming connections using tcpaccept(listener,mode).
Code:

client=tcpaccept(listen,1);
if client<=0 exit;
user[users]=client;
users+=1;
The tcpaccept() script, like tcplisten(), returns a value equal to or less than 0 if an error occurred, or in this case, if no one connects. The blocking/non-blocking comes into play here because if the listener's mode is set to blocking, the host will freeze until someone connects.

On the client side, the first step is to connect to a server using tcpconnect().
Code:

tcpconnect(IP,port,mode);
IP - The IP or URL to connect to.
Port - The port to try to open a connection to.
Mode - Blocking is 0, non-blocking is 1, and the non-blocking+ is 2.
The 3rd mode doesn't freeze the game while the client is connecting. If you do use this, you must use tcpconnected().
Code:

tcpconnected(port);
Port - The port to check if a connection has been established.

This function returns 'true' if the connection has been made.
This all works together like this:
Code:

<create>
server = tcpconnect("127.0.0.1",4444,2);
if (server<=0) {
    show_message("Error: "+string(server));
    game_end();
}
connect=false;

<step>
if !connect {
    connect=tcpconnected(4444);
} else {
    //networking here
}

Sending Data-

The basic message consists of four lines of code, using 4 different functions, clearbuffer(buffer), writebyte(buffer), sendmessage(player,buffer), and whichever write*(value,buffer) function you need to store your message. Game Maker only uses one variable type, so I'll overview the system:

Memory
Bit - A 1 or a 0.
Byte - 8 bits, represents a number or value via binary.

Variable
name - values - size
Boolean - true/false - 1 bit
Short - ±32767 - 2 bytes
U Short - 0 to 65536 - 2 bytes
Integer - ±2147483647 - 4 bytes
U Integer - 0 to 4294967296 - 4 bytes
Float - A number containing a decimal - 4 bytes
Double - Can handle any number GM can - 8 bytes
Char - 1 Ascii character - 1 byte
String - A sequence of characters - length bytes

The buffer is what you actually write the data to, leave that argument blank or use 0 to set the buffer to default.

Write:
Code:

clearbuffer();
writebyte(0);
writeshort(x);
writeshort(y);
sendmessage(receiver);
Read:
Code:

size=recievemessage(sender);
if size<=0; exit;
mid=readbyte();
switch mid {
    case 0:
        val=readshort();
        break;
}

Alright, that pretty much overviews 39DLL.dll programming. Any questions?

2On topic of coding. Empty Re: On topic of coding. Wed Aug 19, 2009 11:01 am

Admin

Admin
Cii Adept Gamer
Cii Adept Gamer

Your A GENIUS!!!!

https://ciiforum.forumotion.net

3On topic of coding. Empty Re: On topic of coding. Wed Aug 19, 2009 11:11 am

link3000

link3000
Cii Adept Gamer
Cii Adept Gamer

Admin wrote:Your A GENIUS!!!!
Whadayya talking about? This is basic programming! Very Happy

4On topic of coding. Empty Re: On topic of coding. Wed Aug 19, 2009 1:20 pm

Admin

Admin
Cii Adept Gamer
Cii Adept Gamer

No kidding. I couldn't learn this if I tried. Well, I could but I haven't tried.

https://ciiforum.forumotion.net

5On topic of coding. Empty Re: On topic of coding. Wed Aug 19, 2009 1:53 pm

link3000

link3000
Cii Adept Gamer
Cii Adept Gamer

Actually, once you get past the beginner stuff that I used to make an example, and get to actual multi-user interfaces, it gets to the point of banging your head on the nearest hard object.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum