LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-22-2008, 09:14 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 20

Rep: Reputation: 0
creating a sender socket blocks a listening socket

Hello everyone,
I am stuck in a problem. Its a PERL socket programming problem. This is whats happening.

I have a server that has two sockets. One socket($listen_socket) for listening any incoming request and One socket($sendingSocket) that will send a reply to one client only.(Actually it is a server that will only listen from one client and reply to that client). Here is my code

$listen_socket = new IO::Socket::INET(LocalHost => '',      LocalPort => xxxx, Proto => 'tcp', Listen => 10, Reuse => 1);

$sendingSocket = new IO::Socket::INET(PeerHost => 'different IP', PeerPort => 'same port as the server', Proto => 'tcp');

while($newSocket = $listen_socket->accept())
   while($newSocket->recv($data, 10000))
      print "Data Received : ".$data."\n";
      if($sendingSocket eq "")
         # create sendingSocket again
         print "done \n";
   close $newSocket;
close $listen_socket;
Now the problem is if client sends any request to server, server receives the first request, and sends a reply... after that it receives an empty msg from client and after that does not receive any request from the client. so when ever i send a reply the listening socket just totally stops listening. why is it happening

Pls reply

Old 09-22-2008, 12:11 PM   #2
Senior Member
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 59
try and put print statements before and after each 'while' line as well as before and after the close statements. post the updated code along with the exact output. in doing this we should be able to see exactly where it appears to be stopped listening.
Old 09-22-2008, 06:55 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 16,678

Rep: Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159Reputation: 2159
Show the client code also


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
500 OOPS: could not bind listening IPv4 socket error raevian Slackware 1 11-27-2007 01:53 AM
Why server socket listen() is not listening seungtaeh Linux - Networking 1 03-09-2007 04:32 AM
Listening socket not released immediately Xagafinelle Programming 4 08-20-2004 05:28 PM
UDP server with socket listening on all IP addresses XTF Programming 0 06-04-2004 03:19 PM
Could not bind listening socket chabotrobert Linux - Networking 1 10-29-2003 12:36 PM

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration