network_connect

语法:

network_connect(socket, url, port);


参数 描述
socket 所使用的套接字id。
url 待连接的URL或IP(字符串形式)。
port 待连接的端口。


返回: Real(实数)


描述

你能够使用该函数发送一个连接服务器的请求。The function takes the socket id to connect through (see network_create_socket) and requires you to give the IP address to connect to (a string) as well as the port to connect through, and if the connection fails a value of less than 0 will be returned. The connection uses a special protocol that ensures only GameMaker Studio 2 games connect to each other, however if you need to connect to a server that is not a GameMaker Studio 2 game, you can use network_connect_raw. Note that by default the function is synchronous, meaning that your game may appear to "hang" as the connection is made. You can set a timeout value for connection, or alternatively make the creation asynchronous, using the function network_set_config().


例如:

client = network_create_socket(network_socket_tcp);
network_connect(client, "192.134.0.1", 6510);

上述代码会新建一个TCP套接字然后尝试通过之去连接指定的IP地址的6510端口。