Jump to content

Fsockopen Error


supertrucker

Recommended Posts

I get this:

Warning: fsockopen() [function.fsockopen]: unable to connect to 66.79.171.227:6667 (Permission denied) in /hermes/bosweb/web237/b2379/sl.supertru/public_html/mygb/irc_bot.php on line 12
Any reason why it would tell me "Permission denied"? Is there some way to turn these permissions on?Here's the original calling line:
	 $config = array(	  'server' => '66.79.171.227', // is actually irc.villageirc.net, I tried the ip when the nice url didn't work	  'port' => 6667,	  'nick' => 'IsABot',	  'name' => 'BotName',	  'pass' => 'meh',	  );	  $bot = new IRCBot( $config );	  $this->socket = fsockopen( $config['server'], $config['port'] );

Pretty simple, it's my experiment with creating a really simple "Chat Bot", and this code is actually a snippet off of an example of a chat bot script. But, I can't even connect to start with!Any ideas?Thanks,Update: I gave up on this after no reply, and tried to use the available Pear classes. I copied one of their examples verbatim, and also get a "Permission Denied". Am I missing something here? Something must be disabling socket connections??? Anybody know where to start looking? Other ideas??ST

Link to comment
Share on other sites

Here's the script in its' entirety:

<?php//So the bot doesnt stop.set_time_limit( 0 );ini_set( 'display_errors', 'on' );class IRCBot{	  var $socket;	  	  function __construct( $config ) //Connects to the server defined later.	  {	  $this->socket = fsockopen( $config['server'], $config['port'] );	  $this->login( $config );	  $this->main();	  }	  function login( $config ) //Sets the bot's Nick and password, as defined later.	  {	  $this->send_data( 'USER', $config['nick'].' iscripting.net '.$config['nick'].' :'.$config['name'] );	  $this->send_data( 'NICK', $config['nick'] );	  }	  function main() //Gets data from server to display in browser.	  {	  $data = fgets( $this->socket, 128 );	  echo nl2br( $data );	  flush();	  $ex = explode(' ', $data);	  if( $ex[0] == 'PING' ) $this->send_data( 'PONG', $ex[1] ); //Plays ping-pong with the server to stay connected.	  $command = str_replace( array( chr(10), chr(13) ), '', $ex[3] );	  switch( $command ) //List of commands the bot responds to from a user.	  {	  case ':!join':	  $this->join_channel( $ex[4] );	  break;	  case ':!quit':	  $this->send_data( 'QUIT', 'Fail.' );	  break;	  }	  $this->main();	  }	  function send_data( $cmd, $msg = null ) //displays stuff to the broswer and sends data to the server.	  {	  if( $msg == null )	  {	  fputs( $this->socket, $cmd."\r\n" );	  echo '<strong>'.$cmd.'</strong><br />';	  }	  else	  {	  fputs( $this->socket, $cmd.' '.$msg."\r\n");	  echo '<strong>'.$cmd.' '.$msg.'</strong><br />';	  }	  }	  function join_channel( $channel ) //Joins a channel, used in the join function.	  {	  if( is_array( $channel ) ) foreach( $channel as $chan ) $this->send_data( 'JOIN', $chan );	  else $this->send_data( 'JOIN', $channel );	  }	  }	  //Example connection stuff.	  // IP is actually irc.villageirc.net, I tried the ip when the nice url didn't work	  $config = array(	  'server' => '66.79.171.227',	  'port' => 6667,	  'nick' => 'IsABot',	  'name' => 'BotName',	  'pass' => 'meh',	  );	  $bot = new IRCBot( $config );	  ?>

Link to comment
Share on other sites

Try connecting to a different server, that you know works. If it can connect to one and not another then the problem is with the remote server. If both of them act the same, try running the script on a different server, preferably one that is not part of a shared host. Try to figure out if the error is coming from the local or remote server. If you're running this on a shared host there's a chance that fsockopen is disabled.

Link to comment
Share on other sites

I am on a shared host, StartLogic to be precise. I ran another example I found on http://php.net for fsockopen and it ran flawlessly:

<?php$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);if (!$fp) {echo "$errstr ($errno)<br />\n";} else {$out = "GET / HTTP/1.1\r\n";$out .= "Host: www.example.com\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)) {echo fgets($fp, 128);}fclose($fp);}?>

So that works. I tried the examples that came with the Pear library for the "SmartIRC", and the standard PHP examples I found, and I keep running into the same error, "Permission Denied". Apparently there is no real documented error codes for SmartIRC so it doesn't really help much [Error code (851)]. Is it possible that the shared server I'm on is denying server requests to go through a specific port?? I.e., 6667 which is the most common port used with IRC. This wouldn't make much sense, though, when they preinstalled the SmartIRC Pear libraries on their servers for us!I'm confused. All I wanted was a simple IRC bot to keep a channel open!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...