CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Problem with socket - server not reacting: Edit Log

New User

Oct 31, 2012, 4:05 AM

Views: 1753
Problem with socket - server not reacting

Hello everyone,

I'm currently working on a custom XMPP server written in Perl. Doing so, I've run into problems with the server not printing out client messages or not replying to messages respectively. The code is as follows:

use IO::Socket;
use IO::Select;

my $server = new IO::Socket::INET(LocalHost => '', LocalPort => '5222', Proto => 'tcp', Listen => '1', Reuse => '1')
or die "Server not running: $!\n";

while(1) {
while($client = $server->accept()) {
print "Client connected...\n";
my $counter = 0;
while(<$client>) {
print "$_\n";
$counter = $counter + 1;

if($counter == 2) {
$data = "<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream=''
xmlns='jabber:client' from='' id='6ba08026' xml:lang='en' version='1.0'>
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<compression xmlns=''>
<auth xmlns=''/>
<register xmlns=''/>
or die "Failed to send message: $!";

As you can see it is currently barely a real server but only counts client messages and replies with a fixed message after a certain amount of messages received. When I run the program and connect to the server using a (proprietary -> developed at my university) client I get the following output:

Client connected...
<?xml version="1.0"?>

<stream:stream xmlns:stream="" version="1.0" xml
ns="jabber:client" to="" xml:lang="de" xmlns:xml="

Then, after a short time, I get a timeout on the client. Using Wireshark I can see, that the first two client messages are received as expected and that on the TCP layer the corresponding ACK messages are exchanged. However, after that for ten second nothing is happening and then the client sends a [FIN, ACK] on TCP, thereby terminating the connection. The strange thing is, that immediately after receiving the [FIN, ACK] the server sends the message implemented in the program above, however, it is ignored by the client and instead it sends a TCP RST.

Using the PSI jabber client I see the same messages as above but I get no timeout. However, when switching the client back to "offline" the server suddenly displays that it has received the following additional message:

<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>

One more strange thing is, that when I remove the trailing "\n" from "print '$_\n'", the last message mentioned before will no be displayed.

For me it seems that the server might be somehow stuck when reading/writing to the socket, however, I can't figure out why and using google I couldn't find any useful information.

Does anyone of you have an idea what could be going wrong? Am I using the socket in a wrong way?

Kind regards,

(This post was edited by Trench on Oct 31, 2012, 4:07 AM)

Edit Log:
Post edited by Trench (New User) on Oct 31, 2012, 4:07 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives