mIRC Home    About    Download    Register    News    Help

Print Thread
#258027 05/06/16 11:50 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
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

Last edited by TillableToast; 05/06/16 11:53 AM.

Life is potato.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Are the messages terminated with a linebreak?

Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
No, it just sends the message on line 1 I would assume


Life is potato.
Joined: Jun 2015
Posts: 84
F
Babel fish
Offline
Babel fish
F
Joined: Jun 2015
Posts: 84
Question:
Is %msg being assigned a value?

Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
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

Last edited by TillableToast; 05/06/16 12:18 PM.

Life is potato.

Link Copied to Clipboard