I use listenexample.sp example:
PHP Code:
// listening socket example for the socket extension
#include <sourcemod>
#include <socket>
public Plugin:myinfo = {
name = "listen socket example",
author = "Player",
description = "This example provides a simple echo server",
version = "1.0.1",
url = "http://www.player.to/"
};
public OnPluginStart() {
SocketSetOption(INVALID_HANDLE, DebugMode, 1);
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
SocketBind(socket, "0.0.0.0", 50000);
SocketListen(socket, OnSocketIncoming);
}
public OnSocketIncoming(Handle:socket, Handle:newSocket, String:remoteIP[], remotePort, any:arg) {
PrintToServer("%s:%d connected", remoteIP, remotePort);
SocketSetReceiveCallback(newSocket, OnChildSocketReceive);
SocketSetDisconnectCallback(newSocket, OnChildSocketDisconnected);
SocketSetErrorCallback(newSocket, OnChildSocketError);
SocketSend(newSocket, "send quit to quit\n");
}
public OnSocketError(Handle:socket, const errorType, const errorNum, any:ary) {
LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(socket);
}
public OnChildSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:hFile) {
SocketSend(socket, receiveData);
if (strncmp(receiveData, "quit", 4) == 0) CloseHandle(socket);
}
public OnChildSocketDisconnected(Handle:socket, any:hFile) {
CloseHandle(socket);
}
public OnChildSocketError(Handle:socket, const errorType, const errorNum, any:ary) {
LogError("child socket error %d (errno %d)", errorType, errorNum);
CloseHandle(socket);
}
Then I use PHP's fsockopen function to send a string. Like this:
PHP Code:
function fsgetdata( $port, $send)
{
$fp = fsockopen("tcp://127.0.0.1", $port, $errno, $errstr, 1);
if (!$fp) {
return -1;
}
stream_set_timeout($fp, 2);
fwrite($fp, $send);
$status = stream_get_meta_data($fp);
if( $status['timed_out'] ) {
fclose( $fp );
return -2;
}
$data .= fread($fp, 4096);
//while (!feof($fp)) //This will generate PHP 30 second timeout
// $data .= fgets($fp, 512);
$data = trim($data, chr(255));
$status = stream_get_meta_data($fp);
fclose($fp);
return !$status['time_out'] ? $data : -2;
}
$ch = fsgetdata( 50000, "Some msg for test");
echo "[".$ch."]";
//If not start the server, output "-1"
//Else Was not able to show anything
Does not display any messages to the console. There is no record of any log.
I used: CS:GO latest version of yesterday. MM :1.9.2 . SM 1.5-hg3786