Jump to content

Socket_write() function question


Undoubtedly0

Recommended Posts

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

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.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.