GMS 2 Socket question!

Jihl

Member
Hey there!

I have an unusual question about sockets.

Is it only neccesary to use the network_destroy function when I need to change a socket type? When should I use this function in game maker? Does it have any importance if I want to connect to different servers over the time?

Thanks!
 

Mert

Member
It is not possible to do that since both TCP and UDP work differently.

  • When you create a TCP socket, it sends some data in the background to establish a communication. This is very much needed for TCP to sustain its connection. UDP does not do that(Tried to explain it as easy as possible)
  • You can create two sockets, a UDP and a TCP. Both can work simultaneously.
  • network_destroy function is used for disconnecting from the server. Can be used when closing the game.
It's not a good strategy keep closing & opening the socket. In need of something like this, I'd use http_request
 
Last edited:

Jihl

Member
It is not possible to do that since both TCP and UDP work differently.

  • When you create a TCP socket, it sends some data in the background to establish a communication. This is very much needed for TCP to sustain its connection. UDP does not do that.
  • You can create two sockets, a UDP and a TCP. Both can work simultaneously.
  • network_destroy function is used for disconnecting from the server. Can be used when closing the game.
It's not a good strategy keep closing & opening the socket. In need of something like this, I'd use http_request
Hey! Thanks for the reply!

Answering your reply.
So the socket shouldn't give any problems if I don't destroy it when disconnecting from server A and then connecting to server B?

The reason why I'm asking this is because I'd like to have a constant-stable connection between my clients and servers, so I thuoght that network_destroy would have been needed while doing this, that's all.

Thanks!
 

Mert

Member
Hey! Thanks for the reply!

Answering your reply.
So the socket shouldn't give any problems if I don't destroy it when disconnecting from server A and then connecting to server B?

The reason why I'm asking this is because I'd like to have a constant-stable connection between my clients and servers, so I thuoght that network_destroy would have been needed while doing this, that's all.

Thanks!
Oh, I believe you're talking about "if my connection is closed somehow, I'd like to reconnect".

TCP connection automatically does that for you. It reconnects and sustains the connection up until it decides that the connection is impossible! Then it'll return in Network Async Event as async_load[? "type"], which should be equal to network_type_disconnect (Constant). You can try to reconnect if you want.

And yes you can network_destroy & connect again
 

Jihl

Member
Oh, I believe you're talking about "if my connection is closed somehow, I'd like to reconnect".

TCP connection automatically does that for you. It reconnects and sustains the connection up until it decides that the connection is impossible! Then it'll return in Network Async Event as async_load[? "type"], which should be equal to network_type_disconnect (Constant). You can try to reconnect if you want.

And yes you can network_destroy & connect again
Thanks for the clarification!

I've done some testing until now and it seems that I cannot reconnect after losing the connection with a server if I don't destroy the socket and create it again. So I guess I'm going that way, destroying and creating the socket every time

The error message I'm talking about is this:
Code:
ioctlsocket failed with error: -1
Error (0x    2736): Could not set socket option
It happens if I DO NOT destroy my socket before trying to connect again
 

Mert

Member
Thanks for the clarification!

I've done some testing until now and it seems that I cannot reconnect after losing the connection with a server if I don't destroy the socket and create it again. So I guess I'm going that way, destroying and creating the socket every time

The error message I'm talking about is this:
Code:
ioctlsocket failed with error: -1
Error (0x    2736): Could not set socket option
It happens if I DO NOT destroy my socket before trying to connect again
This made me realize that I don't have socket closing function in my WebSockets extension.
Oppss.. :( I'll add it
 
Top