Send a message via an existing active connection

1,022 views
Skip to first unread message

Lord Shevernal

unread,
Dec 4, 2011, 3:12:49 AM12/4/11
to jaxl
I'm trying to keep a connection with the server so the bot will be
online all the time. I'm doing this by "> php startbot.php" in the
shell.

What I'm struggling with it is how to send a message from the
connected bot to another user via an existing connection so I don't
have to connect to server everytime I want to send a message? I'm
trying to send the message via another php instance or a webpage.

Also is the any better way to keep a bot connection alive instead of
the way I'm doing it right now?

Thanks in advanced

Abhinav Singh

unread,
Jul 20, 2012, 4:21:41 AM7/20/12
to ja...@googlegroups.com
Hi Lord/Munir,

For this very exact reason we have an experimental ./jaxlctl with v3.x

If you follow "Debugging" and "Remote Shell" section of https://github.com/abhinavsingh/JAXL/ you will find we already have a way using which:
1) you can attach to a running bot in the background
2) configure it on the fly, even send chat messages, group messages etc....

I think you guys will need a programatic way of doing the same.
Kindly checkout and let me know.

--
Abhinav

On Friday, July 20, 2012 1:32:08 PM UTC+5:30, Misbachul Munir wrote:
I need to do exactly the same thing. Any example please..

Thank you in advanced.

Abhinav Singh

unread,
Jul 30, 2012, 5:56:38 PM7/30/12
to ja...@googlegroups.com
for incoming users, relevant link to read more about jaxlctl has moved to:

Murali Krishna P

unread,
Aug 2, 2012, 10:40:39 AM8/2/12
to ja...@googlegroups.com

Hey abhinav when i use ur last link.

i got this errors
jaxl_exception:48 - 2012-08-02 14:38:19 - got jaxl exception construct with Call to a member function send_chat_msg() on a non-object, 1, /home/xmpp/JAXL/jaxlctl(135) : eval()'d code, 1


jaxl_exception:48 - 2012-08-02 14:37:10 - got jaxl exception construct with Call to a member function send() on a non-object, 1, /home/xmpp/JAXL/jaxlctl(135) : eval()'d code, 1

Abhinav Singh

unread,
Aug 2, 2012, 1:48:13 PM8/2/12
to ja...@googlegroups.com
Hi Murali,

As mentioned in docs, this feature is still experimental and is only for advanced users.
You must be knowing what you are doing here.

It's a pretty bad terminal right now since it doesn't support delete, arrow keys etc. Will change in future.
Probably we need an ncurses implementation. If you can't get going with jaxl interactive console, kindly write 
a sample test script to get your code running.

Finally, error that you pasted only indicated that probably you are calling send_chat_msg on a non-object.
This can happen, since you need to write following in one line (which must import global $xmpp jaxl instance variable in your code)

jaxl 1> global $xmpp; $xmpp->send_chat_msg(....);

currently on jaxl interactive console ";" (semicolon) indicates execute what ever code i have written till now.
to break things in two lines, do this:

jaxl 1> global $xmpp
....       $xmpp->send_chat_msg();

remember i didn't wrote a ";" (semicolon) after 1st statement.

These things might change in future.

--
Abhinav

Murali Krishna P

unread,
Aug 2, 2012, 1:59:35 PM8/2/12
to ja...@googlegroups.com
Same ERROR

global $client
....... $client->send_chat_msg('-14500...@chat.facebook.com','hellojusttesting',null,null);
PHP Fatal error:  Call to a member function send_chat_msg() on a non-object in /home/xmpp/JAXL/jaxlctl(135) : eval()'d code on line 1
jaxl_exception:48 - 2012-08-02 17:59:06 - got jaxl exception construct with Call to a member function send_chat_msg() on a non-object, 1, /home/xmpp/JAXL/jaxlctl(135) : eval()'d code, 1

Abhinav Singh

unread,
Aug 2, 2012, 2:04:26 PM8/2/12
to ja...@googlegroups.com
This is from my terminal here:

$ php examples/echo_bot.php abhina...@jabber.org password
...
...
...
jaxl 1> global $client; $client->send_chat_msg("mailsfo...@gmail.com", "hey");
jaxl_loop:82 - 2012-08-02 18:02:33 - active read fds: 3, write fds: 1

jaxl 2> jaxl_socket_client:188 - 2012-08-02 18:02:33 - sent 169/2660 of data
jaxl_socket_client:189 - 2012-08-02 18:02:33 - <message xmlns="jabber:client" type="chat" to="mailsfo...@gmail.com" from="abhina...@jabber.org/jaxl#80808bf1d4a636716506656cd86026a5"><body>hey</body></message>
jaxl_loop:100 - 2012-08-02 18:02:33 - active read fds: 3, write fds: 0

jaxl 2> 

and yeah i did receive it on my gmail chat.

On Thursday, August 2, 2012 11:29:35 PM UTC+5:30, Murali Krishna P wrote:
Same ERROR

global $client
....... $client->send_chat_msg('-1450041...@chat.facebook.com','hellojusttesting',null,null);

Murali Krishna P

unread,
Aug 2, 2012, 2:43:04 PM8/2/12
to ja...@googlegroups.com
Finally WORKED!!!!


But i want it separately. like from another file i wanted to send?
send.php?id=xx...@gmail.com&msg="hello"




On Thursday, August 2, 2012 11:34:26 PM UTC+5:30, Abhinav Singh wrote:
This is from my terminal here:

$ php examples/echo_bot.php abhina...@jabber.org password
...
...
...
jaxl 1> global $client; $client->send_chat_msg("mailsforab...@gmail.com", "hey");

Abhinav Singh

unread,
Aug 2, 2012, 4:00:38 PM8/2/12
to ja...@googlegroups.com
Murali that is something you need to do yourself.
As of now in v3.x there is no way to do this.

Yes there is a way, but you need to work on that yourself.
Jaxl v3.x which you are using for XMPP client also supports HTTP protocol.
Simply start a HTTP server which receives your HTTP GET request,
contact to the running XMPP daemon via IPC or directly if they are running within the same instance.
Finally, HTTP server can serve you what you need.

Brian Baligad

unread,
Dec 6, 2013, 12:57:31 AM12/6/13
to ja...@googlegroups.com
Here's a simple way to do this. Start your jaxl client --with-unix-sock, then you can write to the socket from another script:
<?php
$message = $argv[1];
$socket = "unix://" . dirname(__FILE__) . "/JAXL/.jaxl/sock/jaxl_XXXX.sock";
$fp = stream_socket_client( $socket, $errno, $errstr);
if( !$fp )
{
  printf( "ERROR: $errno - $errstr\n" );
}
else
{
  fwrite( $fp,"$message\n" );
  $response =  fread( $fp, 1024 );
  printf( "$response\n" );
  fclose( $fp );
}

Then try it out:
$ php test.php "quit;"
That's the gist of it basically. You'll just need to find the sock filename before this will work.  JAXL is very impressive and useful!  Thank you Mr. Singh.

Jack Sun

unread,
May 2, 2014, 6:47:22 AM5/2/14
to ja...@googlegroups.com

Hi, 

I am able to create a sock file by echo_bot.php. 

    > php echo_bot.php us...@myxmpp.server.com password 

And try this "test_send_message.php" included in JAXL 3 package. My question is what  data format of $message should be? So that I can send message to som...@myxmpp.server.com through the socket. 

My intention is to set the message string then run the "php test_send_message.php message", then I expect that som...@myxmpp.server.com can get the message from socket creator (us...@myxmpp.server.com). 

<message xmlns="jabber:client" from="us...@myxmpp.server.com" to="som...@myxmpp.server.com" type="chat"><body>Hello World !!!</body></message>

Thanks!!

Jack Sun

unread,
May 15, 2014, 9:53:09 PM5/15/14
to ja...@googlegroups.com
Hi, 

I have figured out how to send out message through unix socket. 

Below is quick memo. 

1. Add a new function in echo_bot.php


function sendMessage($to, $msg)

{

global $client;

$client->send_chat_msg($to, $msg);

}



2. Using JAXL Examples/send_message.php with little modification. 

send_message.php

<?php


require_once '../jaxl.php';


global $client;


$message = $argv[1];

$socket_file_name = $argv[2];

$socket = "unix:///PATH_TO_JAXL/.jaxl/sock/" . $socket_file_name;


$fp = stream_socket_client( $socket, $errno, $errstr);

if( !$fp )

{

printf( "ERROR: $errno - $errstr\n" );

}

else

{

fwrite( $fp,"$message\n" );

$response =  fread( $fp, 1024 );

// printf( "$response\n" );

fclose( $fp );

}



3. execute send_message.php with two parameters sendMessage($to, $message) and socket file

> php send_message.php "sendMessage(\"1...@myxmppserver.com\", \"Hello this is jack sun from server --- demo \");"  jaxl_35252.sock



Thanks for the excellent JAXL!!


-Jack



Jack Sun於 2014年5月2日星期五UTC+8下午6時47分22秒寫道:
Reply all
Reply to author
Forward
0 new messages