Current location: Hot Scripts Forums » Programming Languages » Perl » perl xml socket server ... stuck


perl xml socket server ... stuck

Reply
  #1 (permalink)  
Old 02-27-05, 08:40 AM
cloudiam cloudiam is offline
New Member
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
perl xml socket server ... stuck

We are developing flash multiplayer games since 2001 and lately decided to use perl as socket server to make those games more reliable.

We found some samples of the socket server on the web and adjust them to meet our needs.

Finally we developed final version that was working fine ... well .. working fine until it ... stuck! ...

Not crash ... not generating error ... just stuck ... and it stucks without any pattern or rule .. it stucks on the Windows web server and on the Linux as well.

We tried everything from NON-blocking mode .. till SIGALARM for closing opened connections .... nothing worked.

Perl version installed is 5.8

Please have on mind that we needed server that receive data and send them to all connected users .. Flash is doing rest of the job.

Here is the code, and any help would be great

Tnx in advance ...


use IO::Socket;
use IO::Select;

$SIG{PIPE}='IGNORE';
$m=new IO::Socket::INET(Listen=>1,LocalPort=>9098,Reuse=> 1);
$O=new IO::Select($m);
$/="\0";
$id=0;
$soketi=0;
$timeout=false;
$strel="%3E%3E";
@users=();
$imeigre="Klikado";

$port=$m->sockport();
print "-=< Perl server V1 >=--------- P:$port ------\n\n";
print " www.green-vector.hr\n";
print " $imeigre\n";
print "--------------------------------------------\n";

sub xlat {
my $N = shift;
foreach $E(@users) {
if ($E->[3]==$N) {
return $E;
}
}
}

sub xterm {
my $N = shift;
foreach $idx(0..$#users) {
if ($users[$idx]->[3]==$N) {
delete $users[$idx];
return;
}
}
}

while(@S=$O->can_read){
foreach(@S){
if($_==$m){
$timeout=false;
eval
{
local $SIG{ALRM} = sub { $timeout=true;die ""; };
alarm 10;
$C=$m->accept;
alarm 0;
};

if ($timeout==false) {
$O->add($C);

foreach $D($O->handles){
if ($D!=$m) {
eval
{
local $SIG{ALRM} = sub { die ""; };
alarm 10;
$T=syswrite($D,"$soketi".$strel."Joined ".$C->peerhost().":".$C->peerport()." as client[$id]\0",2048);
alarm 0;
};
}
}
$#users++;
$users[$#users]->[0]="unknown";
$users[$#users]->[1]="free";
$users[$#users]->[2]=$id;
$users[$#users]->[3]=$C;
$id++;
$soketi++;
}
}
else{
$timeout=false;
eval
{
local $SIG{ALRM} = sub { $timeout=true; die "";};
alarm 10;
$R=sysread($_,$i, 2048);
alarm 0;
};

$X=xlat($_);

if ($timeout!=false) {
$T=syswrite($_,'', 2048);
if($T==undef){
foreach $C($O->handles) {
if ($C!=$m) {
eval
{
local $SIG{ALRM} = sub { die ""; };
alarm 10;
$T=syswrite($C,$X->[2].$strel."gone\0",2048);
alarm 0;
};
}
}
xterm($_);
$O->remove($_);
$soketi--;
}
}
else {
$i=~ s/\0//;

if ($i eq "uigri$strel$strel$strel") {
$X->[1]="uigri";
}

if ($X->[0] eq "unknown") {
$X->[0]=$i;
foreach $C($O->handles) {
if ($C!=$m) {
$Y=xlat($C);
eval
{
local $SIG{ALRM} = sub { die ""; };
alarm 10;
$T=syswrite($_,$Y->[2].$strel.$Y->[0].$strel.$Y->[1]."\0",2048);
alarm 0;
};
}
}
}

if($R==0){
$T=syswrite($_,'', 2048);
if($T==undef){
foreach $C($O->handles) {
if ($C!=$m) {
eval
{
local $SIG{ALRM} = sub { die ""; };
alarm 10;
$T=syswrite($C,$X->[2].$strel."gone\0",2048);
alarm 0;
};
}
}
xterm($_);
$O->remove($_);
$soketi--;
}
}
else{
foreach $C($O->handles){
if (($C!=$_) && ($C!=$m)) {
eval
{
local $SIG{ALRM} = sub { die ""; };
alarm 10;
$T=syswrite($C,$X->[2].$strel.$i.$strel.$X->[1]."\0",2048);
alarm 0;
};
}
}
}
}
}
}
}
Reply With Quote
  #2 (permalink)  
Old 02-27-05, 10:44 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
I have no answers for you but I do have a few suggestions. I added a use strict; and use warnings; to the top of that code and checked the syntax. It spit back more errors than you can shake a stick at. For starters, I would code it to run under strict. I think that has a lot to do with your problem(s). Second, try to use meaningful names for your variables. I got seasick from having to go back and forth in vi just to follow along with the variable names. And finally, add in some debugging statements to see where things get hosed up. If you can narrow it down I *might* be able to help out a bit more. I've done very little with socket servers so I'm not sure how useful I can be.

Here's a few links that were put together when I was working with sockets:

http://www.gurusnetwork.com/links/289/date/

~Charlie
Reply With Quote
  #3 (permalink)  
Old 02-28-05, 09:32 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Finally we developed final version that was working fine ... well .. working fine until it ... stuck! ...

Not crash ... not generating error ... just stuck ... and it stucks without any pattern or rule .. it stucks on the Windows web server and on the Linux as well.
One more thing I thought of is the port. Make sure the port you are connecting to is not blcoked by a firewall or router. If it was working and then just stoped, this is most likely the problem.

~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free web site, control panel, and dedicated IP with game server purchase for only $25 twastudios General Advertisements 3 10-20-05 06:13 AM
Perl Webserver andy7t Perl 2 01-24-05 03:17 AM
Simple Perl Server, need help. Lachy Perl 3 09-18-04 10:27 PM
Perl Script to parse 1 xml file into many flsh Perl 0 08-09-04 10:21 AM
FREE Team Speak server w/ every purchase of a Call of Duty Server twastudios General Advertisements 0 10-31-03 01:14 AM


All times are GMT -5. The time now is 04:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.