473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

print to socket causes unexpected exit [please help]

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 1819
numberwhun
3,509 Expert Mod 2GB
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
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...
13
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...
8
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...
10
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...
8
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...
3
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...
10
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...
6
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.