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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Trench
New User

Oct 31, 2012, 4:05 AM

Post #1 of 1 (1022 views)
Problem with socket - server not reacting Can't Post

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:


Code
#!/usr/bin/perl 
use IO::Socket;
use IO::Select;

my $server = new IO::Socket::INET(LocalHost => '10.133.0.61', 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='http://etherx.jabber.org/streams'
xmlns='jabber:client' from='10.133.0.61' id='6ba08026' xml:lang='en' version='1.0'>
<stream:features>
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>DIGEST-MD5</mechanism>
<mechanism>PLAIN</mechanism>
<mechanism>ANONYMOUS</mechanism>
<mechanism>CRAM-MD5</mechanism>
</mechanisms>
<compression xmlns='http://jabber.org/features/compress'>
<method>zlib</method>
</compression>
<auth xmlns='http://jabber.org/features/iq-auth'/>
<register xmlns='http://jabber.org/features/iq-register'/>
</stream:features>";
$client->send($data)
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:


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

<stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml
ns="jabber:client" to="10.133.0.61" xml:lang="de" xmlns:xml="http://www.w3.org/X
ML/1998/namespace">


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:

Quote
<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,
Daniel


(This post was edited by Trench 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