tomfmason Posted November 8, 2006 Share Posted November 8, 2006 This should be realitvely simple but I am running into an issue with writing to a socket..Here is the code in question..[code]<?php$config = array();$config['server'] = 'irc.freenode.net';$config['port'] = 6667;$config['nick'] = 'nick';$config['name'] = 'name';$config['host'] = 'localhost';$config['channel'] = '#phpfreaks';$config['password'] = 'password';set_time_limit(0);$con = array();function cmd_send($command, $con) { $put = fputs($con['socket'], $command . "\r\n"); if (!$put) { echo 'Error : Unable to write to the socket'; } else { print (date("[d/m @ H:i]") ."-> ". $command. "\n\r"); } }function startBot($config, $con) { $con['sock'] = fsockopen($config['server'], $config['port']); $firstTime = true; if (!$con['sock']) { echo "Unable to connect to " . $config['server']; } else { while (!feof($con['sock'])) { $con['buffer']['all'] = trim(fgets($con['sock'], 4096)); if ($firstTime == true) { cmd_send('Nick ' . $config['nick'], $con); cmd_send('User ' . $config['nick'] . ' ' . $config['host'] . ' ' . $config['server'] . ' :' . $config['name'], $con); } print date("[d/m @ H:i]")."<- ". $con['buffer']['all'] . "\n"; if(substr($con['buffer']['all'], 0, 6) == 'PING :') { cmd_send('PONG :'.substr($con['buffer']['all'], 0, 6), $con); if ($firstTime == true){ cmd_send('Nick ' . $config['nick'], $con); cmd_send('User ' . $config['nick'] . ' ' . $config['host'] . ' ' . $config['server'] . ' :' . $config['name'], $con); cmd_send("JOIN ". $config['channel'], $con); $firstTime = false; } } elseif ($old_buffer != $con['buffer']['all']) { //do something; } $old_buffer = $con['buffer']['all']; } }} startBot($config, $con); ?>[/code]I am getting the error that fputs is not a valid resource..(in the cmd_send function)..Any suggestions would be great..Thanks,Tom Quote Link to comment Share on other sites More sharing options...
btherl Posted November 8, 2006 Share Posted November 8, 2006 You're calling it $con['sock'] in one function, and $con['socket'] in the other :PI must confess that I have done that hundreds of times.. it's the simplest errors that are the hardest to find. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted November 8, 2006 Author Share Posted November 8, 2006 Yes.. I figured that out a few hours ago and forgot to post it here..lolThanks,Tom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.