Raised This Month: $51 Target: $400
 12% 

Solved Socket flag not work?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wilian159
Member
Join Date: Dec 2013
Old 08-01-2023 , 22:32   Socket flag not work?
Reply With Quote #1

if I try to connect the socket with the flag "SOCK_NON_BLOCKING" it doesn't connect and I get error

3: - Couldn't connect

but if I connect without flag the connection is successful, why?

Work: socket_open("127.0.0.1", "1337", SOCKET_TCP, xError, 0)
Not work: socket_open("127.0.0.1", "1337", SOCKET_TCP, xError, SOCK_NON_BLOCKING)

Does anyone have any idea why one works and the other doesn't?

Socket error with flag SOCK_LIBC_ERRORS = 10035, but it's all right, I'm not sending any data before.

Last edited by wilian159; 08-03-2023 at 01:42.
wilian159 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 08-02-2023 , 04:52   Re: Socket flag not work?
Reply With Quote #2

try to send some data

Last edited by lexzor; 08-02-2023 at 04:52.
lexzor is offline
wilian159
Member
Join Date: Dec 2013
Old 08-02-2023 , 05:11   Re: Socket flag not work?
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
try to send some data
I can receive the data from the game server, but not from outside my bot, do you have any idea why? remembering that without the flag it works normally.
wilian159 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 08-02-2023 , 07:36   Re: Socket flag not work?
Reply With Quote #4

explain the situation better....

you have a local server where the socket is binded to 127.0.0.1:1337?

what does mean "outside my bot" ?

also, you should explain why you want to use non blocking flag if everything it's working without it.

Last edited by lexzor; 08-02-2023 at 07:37.
lexzor is offline
wilian159
Member
Join Date: Dec 2013
Old 08-02-2023 , 08:17   Re: Socket flag not work?
Reply With Quote #5

I have a discord bot running on the ip 127.0.0.1:1337

and in the plugin I implemented a reconnection system in case the discord bot crashes, but if I use it without the flag the server keeps crashing, and with the flag this does not happen., not to mention that the plugin will be used on several servers.
wilian159 is offline
Old 08-02-2023, 08:20
Dragos
This message has been deleted by Dragos. Reason: Wrong answer
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 08-02-2023 , 08:24   Re: Socket flag not work?
Reply With Quote #6

Quote:
Originally Posted by wilian159 View Post
I have a discord bot running on the ip 127.0.0.1:1337

and in the plugin I implemented a reconnection system in case the discord bot crashes, but if I use it without the flag the server keeps crashing, and with the flag this does not happen., not to mention that the plugin will be used on several servers.
Maybe the problem is with your server configuration, not the socket. Did you used python or java for that discord bot?
__________________
sup
Dragos is offline
wilian159
Member
Join Date: Dec 2013
Old 08-02-2023 , 08:26   Re: Socket flag not work?
Reply With Quote #7

Quote:
Originally Posted by Dragos View Post
Maybe the problem is with your server configuration, not the socket. Did you used python or java for that discord bot?
there is no way to be the bot because it works normally when it is without the flag
wilian159 is offline
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 08-02-2023 , 08:31   Re: Socket flag not work?
Reply With Quote #8

Quote:
Originally Posted by wilian159 View Post
there is no way to be the bot because it works normally when it is without the flag
So what are you saying is that without the flag it works, and crashes randomly, and with the flag it does nothing?

In that case, you should try debugging the server itself if the decoding is decrypted, the connect and disconnect work perfectly and can accept more connexions at the same time...

Anyways, you said that this plugin will be used to send a signal to reconnect the discord bot? Then why can't you just add some functions that in case of the connexions lost, just to reconnect?

Or you can try this thread socket module https://forums.alliedmods.net/showthread.php?t=262924
__________________
sup

Last edited by Dragos; 08-02-2023 at 08:36.
Dragos is offline
wilian159
Member
Join Date: Dec 2013
Old 08-02-2023 , 09:13   Re: Socket flag not work?
Reply With Quote #9

the freezing comes because of the attempt to reconnect, without the flag when trying to reconnect it freezes the server, with the flag it simply does not connect, but there is no freezing
wilian159 is offline
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 08-02-2023 , 12:04   Re: Socket flag not work?
Reply With Quote #10

Quote:
Originally Posted by wilian159 View Post
the freezing comes because of the attempt to reconnect, without the flag when trying to reconnect it freezes the server, with the flag it simply does not connect, but there is no freezing
If you say that your server gets freezer without the flag, when it loses the connexion with the telnet, then use what I mentioned above:

https://forums.alliedmods.net/showthread.php?t=262924

It won't freeze the server because it's thread-safe, but be careful of memory leaks. Also, you have a lot of functions you can use to determine that it's still connected to the server by getting the last error code that looks like that and checking if the data was sent to the server or it raised an error code.

Code:
socket_get_last_error_t(ThreadHandler)
__________________
sup
Dragos is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode