Skip to content

MR-0/socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 

Repository files navigation

socket

Socket test - PHP/JS

Use

For use socket, first is necesary run in the server the script
> php -q socket.php
To run the socket.php independent of the terminal window, you can run first screen:
> screen
And the run the script:
> php socket.php
To check running screen scripts:
> screen -ls
To quit screen session:
> screen -X -S <session #> quit\

Or use these:
> nohup php -q socket.php &
Or
> nohup php -q socket.php >/dev/null 2>&1 &
And check if its works with:
> top

If you want quit the socket, you can run these commands
> lsof -l +M -i4 | grep :<port>
where <port> is the socket port
> kill <pid>
where is the process id of the script

Once the script (PHP) socket is running in the server, you can send and receive information via webSockets (JS). The url must be refer to the same port and with ws scheme. For example: ws://localhost:8090/

Check server state

For control check the ports avaible in the server
> nmap server.name.com
And...
> telnet server.name.com 8090
Via SSH to check if you can connect to a specific port in the server

Via proxy server

If you run the socket in a proxy, you must define a route and set the script as a index in that route, because you must match the proxy and socket headerto handshake whit the client.

Client side rout

The route is compound by:

  • protocol -> ws://
  • host -> your.host
  • port -> :8888
  • path -> /path
    The protocol can be 'ws' or 'wss' -for ssl connection-, the host can be literaly or numeric, refer to a ip; the port generaly must be set above 8000. At last, the path can be set or not, depending the type of server you have. If its a proxy, you must set the port redirection, isolate it from the rest of the site. And, was i say early, you must set the script name as a index. In a regular server, you free to setup as you want, even in the same directory, and target the exact url to the script.

References

Use instead

About

Socket test - PHP/JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages