Hi everyone. I'm tasked with exchanging data with another machine via TCP. I have a pretty good understanding of web architecture overall, but working with sockets is new to me and I seem to be missing something. When I use this, it fails:
$remote_machine = fsockopen($destination,$port,$error_number,$error_message,5) or die($error_message . " " . $error_number);
($destination is an IP address, and $port in this case is 63333.)
When executed, this fails with 'Connection refused (111)'. Which makes sense, since this system requires username / password authentication.
What I'm failing to understand is how I get the username and password to the system. I've read several 'tutorials' online and they all show this information being passed after the connection is established.
If I can get authenticated, I must then receive and respond to some JSON formatted data, if that's noteworthy.
TCP is operating at a lower level than whatever type of authentication you are using so the tutorials you've looked at are right the connection has to be established first. Connection refused means the socket couldn't be established, this could be for a number of reasons:
There's no machine with the IP address specified.
There's no program listening on the port specified.
The program listening only accepts connections from the localhost/specific ip addresses
A firewall somewhere in between the two machines is blocking the connection.
And probably others I can't think of at the moment. If you have access try using a program like telnet to make the same connection, see if it gives you the same error.