SA-MP Forums Archive
help - Socket sa:mp - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: help - Socket sa:mp (/showthread.php?tid=347365)



help - Socket sa:mp - dudaefj - 01.06.2012

Hi
I'm trying to learn a bit of socket, mainly about sa:mp protocol

I'm using the BlueG socket plugin to try to get how many players a server has and some other server info.

Do you know the game-monitor? It can get a lot of server info, as players online, map name, gamemode name, maxplayers, password needed and a lot more

So, is possible to get the same information using the socket plugin? how?

I researched a lot about the subject and I found it: http://pastebin.com/WTR6wP8V
It's a way to get some server information using the PHP plugin method, but I don't know much about PHP
I tried, but my best discovery was that this part of code is the responsable for the "socket protocol" information

PHP код:
        $fp = @fsockopen('udp://' $ip$port$errno$errstr,3) or $this->erro($errstr,__LINE__,__FILE__,$errno);
        if(
$fp){
            
$packet 'SAMP';
            
$packet .= chr(strtok($ip'.'));
            
$packet .= chr(strtok('.'));
            
$packet .= chr(strtok('.'));
            
$packet .= chr(strtok('.'));
            
$packet .= chr($port 0xFF);
            
$packet .= chr($port >> 0xFF);
           
            
fwrite($fp$packet.'i');
            
stream_set_timeout($fp,10);
            
fread($fp11);
            
$conInfo=stream_get_meta_data($fp);
            if(
$conInfo['timed_out']){
                
$this->erro("Connection timed out!");
            } 
but I still don't understand and don't know how to use that with BlueG socket plugin

and an other ask about socket (if some knowledgeable soul can help), socket works just with strings?
I mean, a socket is just a packet, or, a string sent to a "target" ?

if anyone has any good source of learning for noobs about socket, I would be grateful if shared

by the way, back to the main question, "what should I write on a socket to get the server information as response"?

thanks


Re: help - Socket sa:mp - dudaefj - 02.06.2012

nobody knows?


Re: help - Socket sa:mp - Jonny5 - 02.06.2012

iv never tried sockets with samp,
but you could learn about sockets in general from ******,
you are not limited to just php for talking to your server,
their are many many languages that support socket programming

a packet is something a socket sends/receives
the data is not limited to a string.(not sure about how your plugin returns data)

the best place for these questions would be in the socket plugin's release thread
but i would first search ****** to get a general understanding of sockets
before you try to use them within samp.

EDIT:
i took a brief look at the plugins natives

I think you have to make your own protocol,
for example
you send "TOTALPLAYERS" from php to server
in the server you use the callback onSocketReceiveData
and compare the data received if it matches "TOTALPLAYERS" you send
from server to php the number of total players connected.

hope this helps some. Most of this will be just learning to use the natives and for you
learn some php or another language that supports socket programming.


Respuesta: Re: help - Socket sa:mp - dudaefj - 02.06.2012

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
iv never tried sockets with samp,
but you could learn about sockets in general from ******,
you are not limited to just php for talking to your server,
their are many many languages that support socket programming

a packet is something a socket sends/receives
the data is not limited to a string.(not sure about how your plugin returns data)

the best place for these questions would be in the socket plugin's release thread
but i would first search ****** to get a general understanding of sockets
before you try to use them within samp.
I've already done, and I'm still doing it (right now, btw)

I've already done some stuffs w/ socket, but nothing hard

and I was reading the irc include of blueG, and it's not so difficult
the harder is to know "what to write on socket to get the right response", for exemple.


Re: help - Socket sa:mp - Jonny5 - 02.06.2012

i edited my post above
but youll need to write your own protocol as far as i can tell


you send from php to server a command "GetPlayers"
on server use the callback onSocketReceiveData
and compare the data received if it == "GetPlayers" then send a packet containing the number of players

if you look up socket handshake i think youll find what i mean .


good luck! and you just made me open my C# to investigate this! thx.


also look at the Tools & Scripts links in the socket plugin thread,
they may be of help esp the Remote Admin GUI
its in vb.net but should shed some light on this for ya.


Respuesta: Re: help - Socket sa:mp - dudaefj - 02.06.2012

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
i edited my post above
but youll need to write your own protocol as far as i can tell


you send from php to server a command "GetPlayers"
on server use the callback onSocketReceiveData
and compare the data received if it == "GetPlayers" then send a packet containing the number of players

if you look up socket handshake i think youll find what i mean .


good luck! and you just made me open my C# to investigate this! thx.


also look at the Tools & Scripts links in the socket plugin thread,
they may be of help esp the Remote Admin GUI
its in vb.net but should shed some light on this for ya.
I already know that
it's not hard, but I don't want it

I want by my server send a socket to an other server (any server) and get some data from it, like the script I sent do (but the script is by php..)


Re: help - Socket sa:mp - Jonny5 - 02.06.2012

then listen on one and send with the other,
you still need to write your own protocol!

youll just be writing all your code in pawn is all.


Respuesta: Re: help - Socket sa:mp - dudaefj - 02.06.2012

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
then listen on one and send with the other,
you still need to write your own protocol!

youll just be writing all your code in pawn is all.
lol
you still don't get it
when I say "any server", I do not mean a specific server that already has a system ready to communicate with mine.
It would be easier...
SA:MP already has your own protocol, I just want to use it. The issue is "how to"

but no matter, I just found a page on ****** that finally helps me

Thanks anyway


Re: help - Socket sa:mp - Jonny5 - 02.06.2012

i see same as the server browser uses
great!

regards,