mIRC Home    About    Download    Register    News    Help

Print Thread
Need help with sockread #258027 05/06/16 11:50 AM
Joined: May 2016
Posts: 50
T
TillableToast Offline OP
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.
Re: Need help with sockread [Re: TillableToast] #258028 05/06/16 12:10 PM
Joined: Jan 2004
Posts: 1,286
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,286
Are the messages terminated with a linebreak?

Re: Need help with sockread [Re: Loki12583] #258029 05/06/16 12:11 PM
Joined: May 2016
Posts: 50
T
TillableToast Offline OP
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.
Re: Need help with sockread [Re: TillableToast] #258031 05/06/16 12:14 PM
Joined: Jun 2015
Posts: 84
F
Fonic_Artes Offline
Babel fish
Offline
Babel fish
F
Joined: Jun 2015
Posts: 84
Question:
Is %msg being assigned a value?

Re: Need help with sockread [Re: Fonic_Artes] #258032 05/06/16 12:15 PM
Joined: May 2016
Posts: 50
T
TillableToast Offline OP
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.