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

[DEV] WebSocket Server - Direct connection between webbrowser and gameserver


Post New Thread Reply   
 
Thread Tools Display Modes
CaptainZidgel
New Member
Join Date: Jun 2020
Old 09-18-2022 , 00:46   Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
Reply With Quote #71

Update: As I suspected, I am an idiot. The issue causing the Invalid Handle error was that my code was in OnPluginStart as opposed to OnAllPluginsLoaded. I plan to get around the lack of ability to select a path endpoint (site.com:port/endpoint) by just using an additional port. However I am now experiencing "Unable to listen on ip: port". Investigating whether this is an issue with my webserver though (most likely).
Original post:
Can someone tell me if I have this right:
I can only create listening servers using
Code:
Websocket_Open(host, port, callbacks...)
where host is the game server's IP.
I assume this is the case because both the author's example programs listen on the same server.
This is actually fine while I'm in dev but in production I'll want to have my game servers on a different server than my webserver. However I still must be doing something wrong, because when I try to use Websocket_Open I get this exception: Invalid Handle 0 (error: 4)
Code:
#include <sourcemod>
#include <tf2_stocks>
#include <entity_prop_stocks>
#include <sdkhooks>
#include <morecolors>
#include <websocket>
WebsocketHandle wsHandle = INVALID_WEBSOCKET_HANDLE;
//----------------------------------------excerpt from OnPluginStart:
{
char txtfile[256];
BuildPath(Path_SM, txtfile, sizeof(txtfile), "configs/mything.cfg");
	
KeyValues kv = new KeyValues("mything");
kv.ImportFromFile(txtfile);

kv.Rewind();
	
char wsHost[64], wsPortStr[12];
kv.GetString("host", wsHost, 64); //this properly reads as my ip string (x.x.x.x)
kv.GetString("port", wsPortStr, 12);
int wsPort = StringToInt(wsPortStr);
delete kv;
PrintToServer("*+*+*+*+*+*+*+*+*+*+*+*+*+ connecting to server @ %s@%i", wsHost, wsPort); //all good here, both server and port are correct. my ws host and game server are on the same ip. my webserver port is 8080. actually my webserver endpoint is :8080/somePath. Is that an issue?
	
wsHandle = Websocket_Open(wsHost, wsPort, wsIncomingCallback, wsErrCallback, wsCloseCallback); //<--- erroring line: full traceback in next block
bool ok = Websocket_Send(wsHandle, SendType_Text, "Hello world!");
}
//-------------------------------------------My Callbacks:
public Action wsIncomingCallback(WebsocketHandle parent, WebsocketHandle child, const char[] host, int port, char protocols[256], char GETPath[2000])
{
	return Plugin_Continue;
}

public void wsCloseCallback(WebsocketHandle socket)
{
	socket = INVALID_WEBSOCKET_HANDLE;
}

public void wsErrCallback(WebsocketHandle socket, const int errType, const int errNum)
{

}
Code:
L 09/17/2022 - 23:24:40: [SM] Exception reported: Invalid Handle 0 (error: 4)
L 09/17/2022 - 23:24:40: [SM] Blaming: websocket.smx
L 09/17/2022 - 23:24:40: [SM] Call stack trace:
L 09/17/2022 - 23:24:40: [SM]   [0] GetArraySize
L 09/17/2022 - 23:24:40: [SM]   [1] Line 171, C:\Users\Jannik\Documents\GitHub\sm-websocket\scripting\websocket.sp::Native_Websocket_Open
L 09/17/2022 - 23:24:40: [SM]   [3] Websocket_Open
L 09/17/2022 - 23:24:40: [SM]   [4] Line 458, /home/steam/steamcmd/tf2/tf/addons/sourcemod/scripting/mything.sp::OnPluginStart
If I want to send out a message, I have to hook incoming messages, store that handle somewhere, then use websocket_send to send something out.
What if I want to create an outgoing message to a foreign server at will? My main desire for websockets is for my game servers to be clients, chiefly.

Last edited by CaptainZidgel; 09-18-2022 at 20:08.
CaptainZidgel is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 11-14-2022 , 10:20   Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
Reply With Quote #72

Quote:
Originally Posted by CaptainZidgel View Post
Update: As I suspected, I am an idiot. The issue causing the Invalid Handle error was that my code was in OnPluginStart as opposed to OnAllPluginsLoaded. I plan to get around the lack of ability to select a path endpoint (site.com:port/endpoint) by just using an additional port. However I am now experiencing "Unable to listen on ip: port". Investigating whether this is an issue with my webserver though (most likely).
The latest development version received another parameter on the incoming connection callback with the `GET /path` used in the connection. It's not included in any released binaries
https://github.com/peace-maker/sm-websocket/pull/4

Quote:
Originally Posted by CaptainZidgel View Post
If I want to send out a message, I have to hook incoming messages, store that handle somewhere, then use websocket_send to send something out.
What if I want to create an outgoing message to a foreign server at will? My main desire for websockets is for my game servers to be clients, chiefly.
This plugin doesn't implement the client side of websockets.
__________________
Peace-Maker 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 13:27.


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