Friday, January 30, 2009

tcpaccept()

This function accepts any incoming connections on a certain listening socket. You must use the tcplisten() script before this one so there is an open listening socket. This script responds to the tcpconnect() script. (The client would use the tcpconnect script and when it got to the server it would be accepted with this script)

Argumento:
This is the socket to listen on. The best way to set this would be to use the tcplisten() script and then set it to a variable and then use that for this argument. Like this:
socket = tcplisten(1337,8,1) //creates the socket
tcpaccept(socket,1) //tells it to accept connections on this socket

Argument1:
Blocking-0/Non Blocking-1 mode.

This function returns the id of the socket. So it is good to set this to a variable for use later. If it doesn't get a connection it will return a negative number. This script should most likely be used
in the step event in a server object so it will constantly be checking if it needs to accept a connection from the client.

Remember in order for this script to work you must already have created a socket using tcplisten().

In actual code the script works like this:

clientSocket=tcpaccept(socket,1) // accept the connections
if clientSocket<=0{ //if it errored
exit //exit this script
}

//if it didn't you can continue scripting here.

Thursday, January 29, 2009

tcpconnect/tcplisten

We have just learned the tcpconnect() and tcplisten() functions. These functions are used in conjunction. On the server you would use the tcplisten() function to create a listening socket and with the client you would use the tcpconnect() function to connect to the socket that the server has opened. Next we will learn to accept the tcp connection using the tcpaccept() script. I just wanted to throw that little tidbit of information in there so you can see where I am going with this.

tcplisten()

This function creates a listening socket to monitor a port for incoming connections. You use this to open up a 'door' for the messages to come to. This function has 3 arguments.

Argument 0:
(A number)The port to listen on. As stated before a port number can be anything from 1024 to 49151

Argument 1:
(A number) This is the max number of people allowed to be connected but not accepted.

Argument 2:
(true or false)Blocking or Non Blocking mode. (0=Blocking, 1=Non-Blocking) This affects the tcpaccept() script. Remember that false=0 and true=1

This function returns the id of the socket or a negative number if it had an error. So you may want to attach a variable to it to check its status easier. This script in action would be used to start a listening socket to accept connections from players. In actual scripting it would be used like this:

listen=tcplisten(1337,8,true) //opens a listening socket and gives it the id 'listen'
if listen<=0{ //if it errors(returns a negative number)
show_message("Could not create listening socket") //tell them
exit //exit the script
}

//the script can continue on here because if it errored it would have been stopped by the above code(exit)

Wednesday, January 28, 2009

tcpconnect()

tcpconnect()

This function creates a TCP socket. A socket is a combination of an IP and a Port. It is like the house address(IP) and the door(port).

Argument 0:
Argument0 is the IP as a string. To connect to your self remember that you can use 127.0.0.1(This is what you will probably be doing until you get some more stuff programmed.) Don’t forget quotes around it!

Argument 1:
Argument 1 is the port. A port number is can be anything from 1024 to 49151

Argument 2:
Argument 2 is for blocking mode. It has 3 options
0 is for blocking mode
1 is for non-blocking mode
2 is for non blocking and non freezing
(according to 39ster)

After it creates the socket it will return the id if it fails it will return a negative number. So when using this particular function it is good to set it to a variable so you can check if it is negative and so you can use it again later.

The tcpconnect() script in action looks like this:

socket=tcpconnect(‘127.0.0.1’, 1337, 1) //create the socket and store it to a variable

if socket<=0{ //if it is negative that means it errored
show_message(“Could not connect”) //so tell them you couldn’t connect
exit //then exit so it doesn’t keep running the script
}

//Since it didn’t error we can continue with the code here. (If it did error it would have exited this script by now.)

Tuesday, January 27, 2009

Putting it together...

I have been using word pictures to try and help you understand the internet terms. This post will be the culmination of them all. First, a little refresher:

An IP is like your computer's address
A port is like a door
A TCP connection is like a mail system
A packet is like a piece of mail.
A socket is a combination of both an IP and a port

So first, your server will open up a door(port) next your client will open a door(port) Then the client will attempt to 'mail' (Send using TCP) a piece of information(a packet) to the server's 'house'(IP address) and in the open door(port) the combination of the house and door is a socket.

That is the basic gist of online communications. You will be sending packets back and forth between a server and a client. These packets can contain many things from a player's x and y position to a chat message.

Socket

A socket is basically an IP and a port used together(If you do not know what those are look at the older posts). An IP is like a home adress and a Port is like a door, when combined you know were you are going and how to get in.

Ports

I am taking blaXun's description of ports because I cannot articulate it better than him:


Let’s say we have a huge city infront of us (the server) and it has many doors…each door has a number…but unfortunately all doors are closed.

These doors would represent a Port.

Unless the city (the Server) opens a door (Port) we can not get in.

It is necessary for the 39dll to know a open Port.

Opening a port is different for each Network-Hardware.

Please check your instruction-booklet or portforward.com

TCP

TCP stands for Transmission Control Protocol. It is sometimes refered to as TCP/IP. TCP is like a messenger, but it delivers messages through the internet. The World Wide Web itself and many E-mail programs use TCP. We will be using a TCP connection to send information between our client and the server.

TCP connections make sure that the data gets to were it needs to go. A UDP(User Datagram Protocol) connection is faster but you will not be sure that the data went through. TCP is designed to always get to the destination but not always so fast.

TCP exchanges pieces of data over the internet called 'packets'. Packets are just the information you are sending.

Saturday, January 24, 2009

blaXun

BlaXun of the GMC has updated his online engine.

I have a lot of respect for him as a game maker. I highly recommend his engines. You can find quite a few along with some theory here.

Wednesday, January 21, 2009

IP

In order to continue I need to define some terms, so this is a little mini series before I keep going

I.P. Address

An IP is basically like an address for your computer. Everyone has a different one. It can be paralleled to a street address. It is your own personal space. It is for your computer and your computer only.

IPs are always written in the format xxx.xxx.xxx.xxx (where ‘x’ is a positive number)

One special IP that can be used for your own computer is 127.000.000.001 (which can be written in short as 127.0.0.1) This is like saying ‘home’ instead of 123 maple st. Whenever you use the IP 127.0.0.1 you mean your own computer.

To find out your own IP I recommend http://www.ip-adress.com/it is very simple. You simply visit the page and it tells you your current IP.

Tuesday, January 20, 2009

dllinit()

dllinit()

It basically starts the 39dll.
It has 3 arguments

Argument 0:
The first is the dll file name. Usually it will be called 39dll.dll but you can rename it if you want I guess. If you just want to use the 39dll.dll you can either write that or just put a '0' and it will still work.

Argument1:
For loading socket functions. Set to true to load socket functions and false to forget about them. Trust me you need them.

Argument2:
Set to true to load utilities. The best I can tell is it loads the last few scripts. They are mostly helpful little functions but not vital. They include:
fileopen()
fileclose()
filewrite()
fileread()
rilepos()
filesetpos()
filesize()
md5string()
md5buffer()
adler32()
bufferencrypt()
iptouint()
uintoip()
netconnected()

dllfree()

dllfree()

It frees the dll. I don't really know why I should do this. I looked it up on wikipedia.com and some other sites. It seems like it just frees it so your computer does not have it loaded anymore. Perhaps it affects performance? Anyway you do not need to understand everything there is to know about freeing a dll to understand what it does and use it effectivly. It closes the dll. Call it at the end of your game.

Note: This dll has no arguments

39dll dicitonary

To help me learn the 39dll and anyone else who comes by here. I will be writing a dictionary on every function. I'll start at the top and continue downward. If I don't know something then I'll find out.

Wish me luck.

As we go and learn the functions we need I'll start making a client/server example