473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

print to socket causes unexpected exit [please help]

1 New Member
Hi, I have strange problem with my perl program. My program consists of two parts, first written in python and second in perl. Perl part is a server, but also uses two sockets for "talking" with gui written in python. Problem is, that from totally unknown reason perl program quits at line, where i'm trying to 'print' anything for AWAY gui socket. Here's part of my code :

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2. use strict; 
  3. use warnings; 
  4. use IO::Socket; 
  5. use threads; 
  6. use Thread::Queue; 
  7. use File::stat; 
  8.  
  9. my $port = $ARGV[0] || 2347; 
  10. my $awayport = $ARGV[1] || 2346; 
  11. my %clients; 
  12. my $queue = Thread::Queue -> new; 
  13.  
  14. #no zombies 
  15. $SIG{CHLD} = 'IGNORE'; 
  16.  
  17. #create the LISTEN socket 
  18. my $listen_socket = IO::Socket::INET->new(LocalPort => $port, 
  19.                                           Listen => 10, 
  20.                                           Proto => 'tcp', 
  21.                  LocalAddr => 'localhost', 
  22.                                           ReuseAddr => 1); 
  23.  
  24.  
  25. print " * Waiting for lock..\n"; 
  26. while(!open(Lockfile,"<.lock.")){} 
  27. close(Lockfile); 
  28.  
  29. # now crate socket for GUI communication, so I can write to gui, for example status, or anything else 
  30. my $guiListenSock = IO::Socket::INET->new(LocalAddr => "127.0.0.1", 
  31.                              LocalPort => 2346, 
  32.                              Proto    => "tcp", 
  33.                              Type     => SOCK_STREAM) 
  34.     or die "Couldn't Crt sock : $@\n"; 
  35.  
  36. open(LCKF,">.lock.lock.") or die("Can't create .lock.lock."); 
  37. close(LCKF); 
  38.  
  39. my $awayConn; 
  40. my $passwd; 
  41. my $login; 
  42.  
  43. warn "Server ready. Waiting for connections on $port ... \n"; 
  44.  
  45. while (my $connection = $listen_socket->accept) { 
  46.    my $child = threads->create ("myFunc", $queue, $connection, $guiListenSock, $awayConn)->detach; 
  47.  
  48. sub myFunc { 
  49.    my ($queue, $socket, $myoutSock, $awaySock) = @_; 
  50.    select($socket);$|=1; # force flushing 
  51.    select($myoutSock);$|=1; 
  52.    select(STDOUT);$|=1; 
  53.    print $myoutSock "DFJDLJLDKFJLDKFJLKDF\n"; # HERE IS A MOMENT WHEN PROGRAM SUDDENLY CRASHES WITHOUT ANY MESSAGE 
  54.         ... 
  55.         .... 
  56.         ... 
  57. }
Apr 13 '08 #1
1 1845
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi, I have strange problem with my perl program. My program consists of two parts, first written in python and second in perl. Perl part is a server, but also uses two sockets for "talking" with gui written in python. Problem is, that from totally unknown reason perl program quits at line, where i'm trying to 'print' anything for AWAY gui socket. Here's part of my code :

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2. use strict; 
  3. use warnings; 
  4. use IO::Socket; 
  5. use threads; 
  6. use Thread::Queue; 
  7. use File::stat; 
  8.  
  9. my $port = $ARGV[0] || 2347; 
  10. my $awayport = $ARGV[1] || 2346; 
  11. my %clients; 
  12. my $queue = Thread::Queue -> new; 
  13.  
  14. #no zombies 
  15. $SIG{CHLD} = 'IGNORE'; 
  16.  
  17. #create the LISTEN socket 
  18. my $listen_socket = IO::Socket::INET->new(LocalPort => $port, 
  19.                                           Listen => 10, 
  20.                                           Proto => 'tcp', 
  21.                  LocalAddr => 'localhost', 
  22.                                           ReuseAddr => 1); 
  23.  
  24.  
  25. print " * Waiting for lock..\n"; 
  26. while(!open(Lockfile,"<.lock.")){} 
  27. close(Lockfile); 
  28.  
  29. # now crate socket for GUI communication, so I can write to gui, for example status, or anything else 
  30. my $guiListenSock = IO::Socket::INET->new(LocalAddr => "127.0.0.1", 
  31.                              LocalPort => 2346, 
  32.                              Proto    => "tcp", 
  33.                              Type     => SOCK_STREAM) 
  34.     or die "Couldn't Crt sock : $@\n"; 
  35.  
  36. open(LCKF,">.lock.lock.") or die("Can't create .lock.lock."); 
  37. close(LCKF); 
  38.  
  39. my $awayConn; 
  40. my $passwd; 
  41. my $login; 
  42.  
  43. warn "Server ready. Waiting for connections on $port ... \n"; 
  44.  
  45. while (my $connection = $listen_socket->accept) { 
  46.    my $child = threads->create ("myFunc", $queue, $connection, $guiListenSock, $awayConn)->detach; 
  47.  
  48. sub myFunc { 
  49.    my ($queue, $socket, $myoutSock, $awaySock) = @_; 
  50.    select($socket);$|=1; # force flushing 
  51.    select($myoutSock);$|=1; 
  52.    select(STDOUT);$|=1; 
  53.    print $myoutSock "DFJDLJLDKFJLDKFJLKDF\n"; # HERE IS A MOMENT WHEN PROGRAM SUDDENLY CRASHES WITHOUT ANY MESSAGE 
  54.         ... 
  55.         .... 
  56.         ... 
  57. }

I am not sure as I haven't done anything with sockets and such, but hopefully one of our experts will be able to guide you in the right direction.

Regards,

Jeff
Apr 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
10941
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the Accept() returns, the thread spins off another thread to handle the request, and then calls Accept() again. This all works fine except that I can find no way to kill the thread that is blocked in the Accept() call when I want to shut down the server. ...
13
2890
by: Nigel J. Andrews | last post by:
This will be a little vague, it was last night and I can't now do the test in that db (see below) so can't give the exact wording. I seem to remember a report a little while ago about tsearch v2 causing unexpected backend exit messages with 7.3.4 and now I'm getting similar messages unpredictably and I can't find the thread in the archives either. What I did was install tsearch2 using share/contrib/tsearch2.sql, which placed everything...
8
2952
by: MLH | last post by:
I use a mouse-down procedure to trap right mouse clicks and CTRL-Right mouse clicks. Running the procedure must put honey or some other sticky substance into my keyboard because subsequent RightMouseClicks run as if they were CTRL-RightMouseClicks I have to close the form and reopen it to clear this behavior. Then, after the first CTRL-RightMouseClick, it starts all over again.
10
1521
by: balzano_1 | last post by:
Hi, im trying to send text from one pc to anther using C socket programming, i used send() to send the text, the text i used to send is a result of a function, the problem is the other side recieves gibbarish, here are server.c and client.c ------------ server.c ------------ #include <stdio.h> #include <stdlib.h> #include <unistd.h>
8
2082
by: Jim | last post by:
Need some comments from anyone willing to help, please. See the code included below. This compiles with GCC on FreeBSD 4.7. The only point of it is to accept a socket connection. Nothing else has been implemented. It does not work. Everything matches how it should be (according to the man pages on the relevant functions). It also matches line by line with code from another application used as a known to be working reference. ...
3
2207
by: ferbar | last post by:
Hello all, This may sound pretty basic stuff.. but I'm working on a socket example whose client seems to work fine, but the server doesn't send to the client the expected result. The problem is that I want to trace what the server socket is doing, but I'm unable to see any of my fprintf or printf stuff. Please take a look to the example:
10
4046
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can anyone please help me with some sample codings and guidance? Can you also suggest some other news group available for socket programming in VB.Net?
6
6595
by: Dilip | last post by:
I don't know how I missed this piece for so long (this may also be old news to you guys) but in this ACMQueue article, Michi Henning goes to elaborate lengths to detail how even today designing a good API requires a lot experience and effort by illustrating the example of something as common place as the select() function call available in sockets. The example focuses on the design decision surrounding the Select() call in C#. It comes...
2
4126
by: apollo135 | last post by:
Dear All, Could someone help and tell me how to handle multiple send and receive operations with udp sockets? In fact here is my problem: server.c is composing of serveral sub programs (the same for client.c) -----server.c------- ................ int main(){ ............
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.