homepage Welcome to WebmasterWorld Guest from 54.161.185.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
confused about fsockopen
not sure I understand the syntax
frobozz

5+ Year Member



 
Msg#: 4196648 posted 9:51 pm on Sep 4, 2010 (gmt 0)

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.

Can someone help me understand the process here?

 

Little_G

5+ Year Member



 
Msg#: 4196648 posted 10:56 pm on Sep 4, 2010 (gmt 0)

Hi,

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.

Andrew

frobozz

5+ Year Member



 
Msg#: 4196648 posted 3:52 pm on Sep 5, 2010 (gmt 0)

Thanks, Little-G. It turned out that I had been given the wrong port number, which explained the connection refusal. Everything is working now.

The syntax of the commands had me confused. It seemed to me that opening a connection inherently involved authentication, so I could not see how I could open a connection and then authenticate myself.

Kind of like a speakeasy operator letting you into the bar and then asking you for the secret password. Didn't make sense.

Apparently, in this case, "opening" the connection (fsockopen) is the equivalent of simply knocking on the door. So now it makes sense. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved