View Single Post
Author Message
Raicha
New Member
Join Date: Apr 2020
Old 04-05-2020 , 16:42   Sourcepawn sockets with python
Reply With Quote #1

OpenSocketStream()
{
new String:serverIP[40];
new longip = GetConVarInt(FindConVar("hostip"));
FormatEx(serverIP, 40, "%d.%d.%d.%d", longip >>> 24 & 255, longip >>> 16 & 255, longip >>> 8 & 255, longip & 255);
if (!ServerSocket)
{
ServerSocket = Websocket_Open(serverIP, GetConVarInt(CVAR_WebsocketPort), OnWebsocketIncoming, OnWebsocketMasterError, OnWebsocketMasterClose);
}
PrintToChatAll("OCTET FLOW STREAM STARTED ! NUDGE OFFSET %i", GetConVarInt(CVAR_WebsocketPort));
return 0;
}

public void:OnPluginStart()
{
CVAR_WebsocketPort = CreateConVar("sm_discord_port", "1337", "WEBSOCKET PORT", 0, false, 0.0, false, 0.0);
ClientSockets = CreateArray(1, 0);
RegAdminCmd("1337wh", SLK, 16384, "", "", 0);
RegConsoleCmd("link", Command_RootAcc, "", 0);
return void:0;
}

I am trying to connect to that socket in python, but it fails, by hanging on. Python code is -
import socket
import json

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

x = '{"RequestType":"35","RemoteLinkPKG":"POST"," RemoteLinkPKG":"1337","SID":"1234","Time":"12 34","Action"."1"}'
y = json.dumps(x)
s.connect(('localhost',1337))
s.send(y)
print s.recv(1024)

Last edited by Raicha; 04-06-2020 at 00:57.
Raicha is offline