Undoubtedly0 Posted July 29, 2009 Share Posted July 29, 2009 Hi all! I was playing around with php functions recently when I got stumped writing a simple function that used socket_write(). Seeing how this function works with printing "hello, world!"... function printmsg($text) { print "Hello, $text"; } printmsg("world!"); //Provides "Hello, world!" ...I couldn't figure out why the following function wasn't providing anything: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); function socketmsg($text) { socket_write($socket, "PRIVMSG #chan Hello, $text\n"); } socketmsg("world!"); Yet I still could provide a message by using socket_write($socket, "PRIVMSG #chan Hello, world!\n");, without the function. Does anyone see what I'm doing wrong here (or does my question make sense?)? Thanks a lot for your help! Link to comment https://forums.phpfreaks.com/topic/167963-socket_write-function-question/ Share on other sites More sharing options...
Adam Posted July 29, 2009 Share Posted July 29, 2009 Variable scope of the $socket variable. Try moving socket_create() to within the function. Link to comment https://forums.phpfreaks.com/topic/167963-socket_write-function-question/#findComment-885930 Share on other sites More sharing options...
Undoubtedly0 Posted July 29, 2009 Author Share Posted July 29, 2009 I moved the socket_create() like you said so it looks like this: function socketmsg($text) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_write($socket, "PRIVMSG #chan Hello, $text\n"); } The problem is that it's still not giving me any response, even though it works like: socket_write($socket, "PRIVMSG #chan Hello, World!"); Is there something else that could be the problem? Thanks again. Link to comment https://forums.phpfreaks.com/topic/167963-socket_write-function-question/#findComment-885977 Share on other sites More sharing options...
Undoubtedly0 Posted August 2, 2009 Author Share Posted August 2, 2009 Hm, I'm stumped. I've tried this in a number of other configurations and it still doesn't work. Does anyone else have any ideas? Link to comment https://forums.phpfreaks.com/topic/167963-socket_write-function-question/#findComment-888884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.