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 : - #!/usr/bin/perl
-
use strict;
-
use warnings;
-
use IO::Socket;
-
use threads;
-
use Thread::Queue;
-
use File::stat;
-
-
my $port = $ARGV[0] || 2347;
-
my $awayport = $ARGV[1] || 2346;
-
my %clients;
-
my $queue = Thread::Queue -> new;
-
-
#no zombies
-
$SIG{CHLD} = 'IGNORE';
-
-
#create the LISTEN socket
-
my $listen_socket = IO::Socket::INET->new(LocalPort => $port,
-
Listen => 10,
-
Proto => 'tcp',
-
LocalAddr => 'localhost',
-
ReuseAddr => 1);
-
-
-
print " * Waiting for lock..\n";
-
while(!open(Lockfile,"<.lock.")){}
-
close(Lockfile);
-
-
#
-
# now crate socket for GUI communication, so I can write to gui, for example status, or anything else
-
#
-
my $guiListenSock = IO::Socket::INET->new(LocalAddr => "127.0.0.1",
-
LocalPort => 2346,
-
Proto => "tcp",
-
Type => SOCK_STREAM)
-
or die "Couldn't Crt sock : $@\n";
-
-
open(LCKF,">.lock.lock.") or die("Can't create .lock.lock.");
-
close(LCKF);
-
-
my $awayConn;
-
my $passwd;
-
my $login;
-
-
warn "Server ready. Waiting for connections on $port ... \n";
-
-
while (my $connection = $listen_socket->accept) {
-
my $child = threads->create ("myFunc", $queue, $connection, $guiListenSock, $awayConn)->detach;
-
}
-
-
sub myFunc {
-
my ($queue, $socket, $myoutSock, $awaySock) = @_;
-
select($socket);$|=1; # force flushing
-
select($myoutSock);$|=1;
-
select(STDOUT);$|=1;
-
print $myoutSock "DFJDLJLDKFJLDKFJLKDF\n"; # HERE IS A MOMENT WHEN PROGRAM SUDDENLY CRASHES WITHOUT ANY MESSAGE
-
...
-
....
-
...
-
}
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 : - #!/usr/bin/perl
-
use strict;
-
use warnings;
-
use IO::Socket;
-
use threads;
-
use Thread::Queue;
-
use File::stat;
-
-
my $port = $ARGV[0] || 2347;
-
my $awayport = $ARGV[1] || 2346;
-
my %clients;
-
my $queue = Thread::Queue -> new;
-
-
#no zombies
-
$SIG{CHLD} = 'IGNORE';
-
-
#create the LISTEN socket
-
my $listen_socket = IO::Socket::INET->new(LocalPort => $port,
-
Listen => 10,
-
Proto => 'tcp',
-
LocalAddr => 'localhost',
-
ReuseAddr => 1);
-
-
-
print " * Waiting for lock..\n";
-
while(!open(Lockfile,"<.lock.")){}
-
close(Lockfile);
-
-
#
-
# now crate socket for GUI communication, so I can write to gui, for example status, or anything else
-
#
-
my $guiListenSock = IO::Socket::INET->new(LocalAddr => "127.0.0.1",
-
LocalPort => 2346,
-
Proto => "tcp",
-
Type => SOCK_STREAM)
-
or die "Couldn't Crt sock : $@\n";
-
-
open(LCKF,">.lock.lock.") or die("Can't create .lock.lock.");
-
close(LCKF);
-
-
my $awayConn;
-
my $passwd;
-
my $login;
-
-
warn "Server ready. Waiting for connections on $port ... \n";
-
-
while (my $connection = $listen_socket->accept) {
-
my $child = threads->create ("myFunc", $queue, $connection, $guiListenSock, $awayConn)->detach;
-
}
-
-
sub myFunc {
-
my ($queue, $socket, $myoutSock, $awaySock) = @_;
-
select($socket);$|=1; # force flushing
-
select($myoutSock);$|=1;
-
select(STDOUT);$|=1;
-
print $myoutSock "DFJDLJLDKFJLDKFJLKDF\n"; # HERE IS A MOMENT WHEN PROGRAM SUDDENLY CRASHES WITHOUT ANY MESSAGE
-
...
-
....
-
...
-
}
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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. ...
|
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...
|
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.
|
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>
|
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. ...
| |
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:
|
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?
|
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...
|
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(){
............
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |