mIRC Homepage
Posted By: TillableToast Need help with sockread - 05/06/16 11:50 AM
Hi so I'm currently working on a way to make a dashboard for my bot. My idea is that I have my website send commands to the bot via sockets though I'm having some trouble.

This is the code that sends the message to my bot (Note this is PHP)
Code:
function sendMsg($msg) {
  $host = "myIp";
  $port = myPort;
  $len = strlen($msg);
  $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
  socket_connect($socket,$host,$port) or die("Could not connect to the socket\n");
  socket_sendto($socket, $msg, $len, 0, $host, $port);
}

Basically what it does is that it sends a string to my VPS which the bot is hosted on, then the bot reads it using this code:
Code:
on *:SOCKLISTEN:www: {  
  sockaccept web $+ $ticks 
  echo -s *** Connection Accepted. 
}
on *:SOCKREAD:web*: { 
  echo -s *** READING MESSAGE
  sockread %msg 
  echo -s MESSAGE: %msg
}


So when I run the PHP code my bot does actually run through the socket events, though it does not fetch the message, it only echoes: MESSAGE: (blank)

NOTE: I have indeed opened up the ports on both ends so it's not a firewall issue

Hope someone out there can help me
Posted By: Loki12583 Re: Need help with sockread - 05/06/16 12:10 PM
Are the messages terminated with a linebreak?
Posted By: TillableToast Re: Need help with sockread - 05/06/16 12:11 PM
No, it just sends the message on line 1 I would assume
Posted By: Fonic_Artes Re: Need help with sockread - 05/06/16 12:14 PM
Question:
Is %msg being assigned a value?
Posted By: TillableToast Re: Need help with sockread - 05/06/16 12:15 PM
Yes ofc smile I just do that by calling the function and parsing it a value like this: sendMsg($message);

EDIT: The %msg variable is equal to what it reads on the socket
© mIRC Discussion Forums