Problem sending message with xmpphp through openfire to other gateways

hello everyone,

i just found out about this openfire thing a couple days ago and i’ve been trying to get it set up and have it working

but i ran into some problems.

for now i already install the plugins for the gateway and i test it and it says that the test is successful

so i assume that it should work no problem.

so i’m trying to use xmpphp to send message to other service using this gateway plugin but i have no luck.

i can use spark client to send message between people in my network and i can also use xmpphp to send

message to other people in my network and it still works but when i try to send the message to my other account

such as aim or msn it’s no longer working.

maybe it’s something simple but i wonder if you guys and help point me in a right direction here

here’s the code that i use that i got from xmpphp

include 'XMPPHP/XMPP.php'; $conn = new XMPPHP_XMPP('testing.domain.com', 5222, 'testtest', 'testing', 'xmpphp', 'testserver.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); try {
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->presence();
    $conn->message('aimtesting@aim.testserver.com', 'This is a test message from php code!');
    $conn->disconnect();
} catch(XMPPHP_Exception $e) {
    die($e->getMessage());
}

(all the names had be changed but it should show what i’m trying to do)

when i try to send a message to my aim account, it doesn’t seem to be getting though and i dont’ know what else to do if anyone can help me that would be great

thank you,

tom

Any luck with this? i too have started to look into this code and have yet to be successful.

hey jeffk,

if what you’re trying to do is trying to send a message to other gateway through the openfire with php then the the xmpphp is not what you’re looking for.

i’ve been going through the codes many times and i don’t think xmpphp can send message to other gateways without already be logged in that gateway in openfire before sending the message but it works great for sending message within openfire server

and i don’t think xmpphp supports gateway discovery and stuff. i might have been wrong about this but i found a new php library that work great

PHP Jabber Client

http://code.blitzaffe.com/pages/phpclasses/files/jabber_client_52-11

it works great. it does everything i needed it to do like discovery, register transport and so on

so it’s up to you which one you would like to use

for the xmpphp, you can make it send message to other gateway through openfire and here’s the code

$conn = new XMPPHP_XMPP(‘jabber.example’, 5222, ‘jabber_username’, ‘jabber_password_here’, ‘xmpphp’, ‘server_name’, $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);

try {
$conn->connect();
$conn->processUntil(‘session_start’);
$conn->presence(“Ya, I’m online”,“available”,“aim.server_name”);
$conn->message(‘someaim@aim.server_name’, ‘This is a test message and i think it is working!’);
$conn->disconnect();
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}

BUT this code will work if you already signed in to that gateway in your openfire…

this is why i think that php jabber client is working better and have more options that you can choose for and stuff

i hope i’m explaining it somewhat clearly. if you have any questions please let me know

ubiquitous_tom

Thanks for the reply.

Essentially I am creating a web app that will send a message to users in out system (we have an internal jabber setup). So all I need is the ability to transmit a message.

I have tried an cannot get the xmpp to connect.

$conn = new XMPPHP_XMPP('192.168.10.29, 5222, ‘username’, ‘password’, ‘xmpphp’, ‘example.com’, $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);

So our server is accessible via the IP Address

example.com is the domain of the user (so in the above example it would be username@example.com)

I will look into PHP Jabber Client but since my usage is so simple I would like to keep it as that. Any suggestions or help is appreciated.

Jeff

I checked out PHP Jabber Client and they do not seperate host and domain (I have accross this a few times (even with spark web)) so I dont think this one will work.

define(“JABBER_SERVER”,“192.168.10.29”);
define(“JABBER_USERNAME”,“username”);
define(“JABBER_PASSWORD”,“password”);

can i see the whole code for this one?

i noticed that you ip starts with 192.168.xxx.xxx. is this like on your network/router or something?

well i think this might have to do with you ip address setting and your server.

i was reading this post about dns and ip address and i don’t know if this is something you’re have a problem with but you might wanna have a look.

and if this is the ip within your network/router then i don’t know what’s wrong with it because i used to use this 192.168.xxx.xxx for my jabber within the network between friends and it works fine so please let me know how it goes for you.

and if you can give me a little snippet of your code that would be great also so i can try it on my end see if it would work… or something that i might be able to help you out with

ps both xmpphp and jabber calls codes please if you can because for me xmpphp seems to be more straight forward then jabber class for what you’re trying to do in my opinion

ubiquitous_tom

Sure…I am essentially using the example from above

I turned on debugging (it was timing out). message below.

<?php include 'xmpphp/XMPPHP/xmpp.php'; $conn = new XMPPHP_XMPP('192.168.10.29, 5222, 'username', 'password', 'xmpphp', 'example.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); try { $conn->connect(); $conn->processUntil('session_start'); $conn->presence(); $conn->message('username2@example.com', 'This is a test message!'); $conn->disconnect(); } catch(XMPPHP_Exception $e) { die($e->getMessage()); } ?>

it outputs

1233114595 [INFO]: Connecting to tcp://192.168.10.29:5222 1233114595 [VERBOSE]: Socket is ready; send it. 1233114595 [VERBOSE]: SENT: 1233114595 [VERBOSE]: Successfully sent 122 bytes. 1233114595 [VERBOSE]: RECV: PLAIN 1233114595 [DEBUG]: Calling features_handler 1233114595 [VERBOSE]: Socket is ready; send it. 1233114595 [VERBOSE]: SENT: 1233114595 [VERBOSE]: Successfully sent 73 bytes. 1233114595 [VERBOSE]: RECV: 1233114595 [DEBUG]: Calling tls_proceed_handler 1233114595 [INFO]: Starting TLS encryption 1233114595 [VERBOSE]: Socket is ready; send it. 1233114595 [VERBOSE]: SENT: 1233114595 [VERBOSE]: Successfully sent 122 bytes.

So it does look like it’s doing something…just not sending a message

Ok for anyone else having issues…xmpphp DOES work but you need to make sure your PHP has the Multi-Byte-String extension enabled. I altered my install of PHP and Presto! all works beautifully.

hi…

i have got a task to connect openfire server with xmpphp client. i tried hard but not got success. When i connect to openfire then only blankpage is shown.

code is as-

<?php session_start(); header('content-type', 'plain/text'); // activate full error reporting //error_reporting(E_ALL & E_STRICT); include ("/XMPPHP/BOSH.php"); print "
";

#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports

#If this doesn't work, are you running 64-bit PHP with < 5.2.6?

$conn = new XMPPHP_BOSH('10.1.0.23', 5222, 'admin', 'asdfghjkl', 'xmpphp', 'hitech.com', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);

$conn->autoSubscribe();

try {

if(isset($_SESSION['messages'])) {

foreach($_SESSION['messages'] as $msg) {

print $msg;

flush();

}

}

    $conn->connect('[http://10.1.0.23:7070/xmpp-httpbind](http://10.1.0.23:7070/xmpp-httpbind)', 1, true);

#while(true) {

$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));

foreach($payloads as $event) {

$pl = $event[1];

switch($event[0]) {

case 'message':

if(!isset($_SESSION['messages'])) $_SESSION['message'] = Array();

$msg = "------------------------------------------------------------------------------ ---\n{$pl['from']}: {$pl['body']}\n";

print $msg;

$_SESSION['messages'][] = $msg;

flush();

$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);

if($pl['body'] == 'quit') $conn->disconnect();

if($pl['body'] == 'break') $conn->send("");

break;

case 'presence':

print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";

break;

case 'session_start':

print "Session Start\n";

$conn->getRoster();

$conn->presence($status="Cheese!");

break;

}

}

#}

} catch(XMPPHP_Exception $e) {

die($e->getMessage());

}

$conn->saveSession();

print "
"; print ""; ?>