network_create_server(type, port, max_client);
参数 | 描述 |
---|---|
type | 要创建的服务器类型(详见以下常量表)。 |
port | 服务端所使用的端口。 |
max_client | 一次性能连接客户端的最大数量。 |
返回: Real(实数)
This function is used to create a new network server for your
game, using one of the permitted connection protocols (see the
constants listed below). You supply the server type, then give it a
port to use, and finally the number of maximum connections that
should be permitted at any one time to the server (note that this
number is up to you, but too many connected clients will saturate
the network or the device CPU won�t be able to handle the
processing of that number of players, so use with care). The
function returns a unique id which should be used stored in
a variable and used to identify the server in all further network
functions, or a value of less than 0 if the connection fails.
常量 | 描述 |
---|---|
network_socket_tcp | 使用TCP协议创建一个网络套接字。 |
network_socket_udp | 使用UDP协议创建一个网络套接字。 |
network_socket_bluetooth | 创建一个蓝牙套接字(尚不可用!) |
var port = 6510;
server = network_create_server(network_socket_tcp, port, 32);
while (server < 0 && port < 65535)
{
port++
server = network_create_server(network_socket_tcp, port, 32);
}
上述代码将会尝试使用TCP协议通过端口6510创建一个服务端。若端口不可用,则会遍历所有端口并找到合适的进行连接。