Raised This Month: $ Target: $400
 0% 

Need help: Socket On CS:GO?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
wwzw
Member
Join Date: Feb 2009
Old 02-22-2013 , 19:48   Re: Need help: Socket On CS:GO?
Reply With Quote #3

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_HANDLEDebugMode1);
 new 
Handle:socket SocketCreate(SOCKET_TCPOnSocketError);
 
SocketBind(socket"0.0.0.0"50000);
 
SocketListen(socketOnSocketIncoming);
}
public 
OnSocketIncoming(Handle:socketHandle:newSocketString:remoteIP[], remotePortany:arg) {
 
PrintToServer("%s:%d connected"remoteIPremotePort);
 
SocketSetReceiveCallback(newSocketOnChildSocketReceive);
 
SocketSetDisconnectCallback(newSocketOnChildSocketDisconnected);
 
SocketSetErrorCallback(newSocketOnChildSocketError);
 
SocketSend(newSocket"send quit to quit\n");
}
public 
OnSocketError(Handle:socket, const errorType, const errorNumany:ary) {
 
LogError("socket error %d (errno %d)"errorTypeerrorNum);
 
CloseHandle(socket);
}
public 
OnChildSocketReceive(Handle:socketString:receiveData[], const dataSizeany:hFile) {
 
SocketSend(socketreceiveData);
 if (
strncmp(receiveData"quit"4) == 0CloseHandle(socket);
}
public 
OnChildSocketDisconnected(Handle:socketany:hFile) {
 
CloseHandle(socket);
}
public 
OnChildSocketError(Handle:socket, const errorType, const errorNumany:ary) {
 
LogError("child socket error %d (errno %d)"errorTypeerrorNum);
 
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$errstr1);
 if (!
$fp) {
  return -
1;
 }
 
stream_set_timeout($fp2);
 
fwrite($fp$send);
 
$status stream_get_meta_data($fp);
 if( 
$status['timed_out'] ) {
  
fclose$fp );
  return -
2;
 }
 
$data .= fread($fp4096);
 
//while (!feof($fp))             //This will generate PHP 30 second timeout
 // $data .= fgets($fp, 512);
 
$data trim($datachr(255));
 
$status stream_get_meta_data($fp);
 
fclose($fp);
 return !
$status['time_out'] ? $data : -2;
}
$ch fsgetdata50000"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

Last edited by wwzw; 02-22-2013 at 19:53.
wwzw is offline
 



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 23:58.


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