After forwarding the port I wish to open, I cannot seem to connect or get any data to this port. The PHP CLI software I have written is listening to the port actively on Ubuntu 14.04. Part of the code is shown below. The port is opened as AF_INET, script throws no errors for each line, and /etc/protocols has tcp defined as 'tcp 6 TCP'.
// I have tried $host=gethostbyname(gethostname());$port=8399 (host is 127.0.1.1)
// as well as $host = '0.0.0.0'; $port = 8399; and other addresses
$this->wsRead[0] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
socket_set_option($this->wsRead[0], SOL_SOCKET, SO_REUSEADDR, 1)
socket_bind($this->wsRead[0], $host, $port)
socket_listen($this->wsRead[0], 10)
while (isset($this->wsRead[0])) { /* Handshake/Process data, etc. */ }
The ports are forwarded and my iptables are empty, although I have tried specifically adding an allow rule for the port. I've tried running the script as super user. When the server is listening, netstat -tuln lists this line (with my port 8399), and I notice apache also listed, which works fine and shows as an open port from external port checking websites (on port 8301):
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:8399 0.0.0.0:* LISTEN
tcp6 0 0 :::8301 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
Using nmap the port shows to be open also. I have tried different ports as well. My client side connection script is a JavaScript websocket script which works to connect when running the PHP CLI on Windows. The script is too long to include here, and it does not connect from external network. If I set both JS and PHP scripts to local addresses 127.0.0.1 or 192.168.0.### then it does work but not from a device outside my LAN.
// The JS is basically this, plus some connection events to alert success/fail.
// This external connection request will always time out
Server = new WebSocket('ws://68.215.154.129:8399');
Am I missing some firewall in Linux besides iptables that I am not bypassing? Apache is getting the ports open correctly and other software on the PC but it appears my script is missing a necessary step to fully open the port for external use.
tl,dr; Connecting using external IP address using JavaScript client to PHP server working on Windows but not on Ubuntu. Port forwarded, listening, not blocked by iptables, what's left?