protosteel
Member
So: I am trying to set up a simple network, and it's going well, but a small issue is bothering me: upon switching to non-blocking connections so that my game doesn't freeze upon attempting a connection, I now can no longer attempt to connect the client to the server multiple times. Create event:
Draw event:
Async networking event:
When it connects, everything works great, but when it doesn't connect (e.g. if the server is down), it assigns an ID for the server socket upon keypress (as per how non-blocking connects work), the connection attempt eventually times out and I reset this value to -1 in the async event, and then subsequent keypresses have no affect - it does not seem to run the "network_connect" function again, ostensibly because this server socket ID still exists (?). I have tried using network_destroy to remove it, but that crashes the game, possibly because it's not an actual socket I'm trying to destroy, just a weird placeholder. Help would be appreciated, thanks.
GML:
socket=network_create_socket(network_socket_tcp)
server=-1
network_set_config(network_config_connect_timeout, 5000)
network_set_config(network_config_use_non_blocking_socket,1)
GML:
if keyboard_check_pressed(vk_f2) and server==-1 {
server=network_connect(socket,ipaddress,9999)
if server>=0 {
show_debug_message("ATTEMPTING TO CONNECT...")
}
}
GML:
if async_load[?"type"]==network_type_non_blocking_connect {
if async_load[?"id"]==socket {
if async_load[?"succeeded"]==1 {
show_debug_message("CLIENT CONNECTED TO "+async_load[?"ip"])
} else {
server=-1
show_debug_message("CLIENT FAILED TO CONNECT")
}
}
}