Skip to content

Instantly share code, notes, and snippets.

View nalkat's full-sized avatar

nalkat

  • Lost in the forest somewhere in the PNW
View GitHub Profile
@nalkat
nalkat / netport_server.php
Last active July 3, 2018 12:59
This is a simple network port server which allows multiple clients to connect, however it does not handle concurrent access.... If anyone has ideas on how to solve it, please let me know. pcntl_fork() on clients did not seem to bear fruit.
<?php // 7.3.0-dev
$clientPort;
$clientIP;
$address = "127.0.0.1";
$port = 9001;
if (($listenSocket = @socket_create(AF_INET, SOCK_STREAM, 0)) === false) exit ("could not create socket");
if ((@socket_set_option($listenSocket, SOL_SOCKET, SO_REUSEADDR, 1)) === false) exit ("could not set the socket to be reusable");
if ((@socket_bind($listenSocket, $address, $port)) === false) exit ("could not bind the socket to the address:port provided");
if ((@socket_listen ($listenSocket)) === false) exit ("could not listen to socket");
if ((@socket_set_nonblock ($listenSocket)) === false) exit("could not set the socket to non-blocking mode");