List Info

Thread: server programing problem




server programing problem
user name
2006-11-21 23:19:09
Hi All,

I'm trying to create a network game where the server part is
a cgi
script and the client is a flash embedded into an html page.
Data
exchange is performed via sockets.

Now I'm using the following scheme: 
a user starts the game by running "start.cgi" in
his browser. Firstly,
this program returns a location to the flash client.
Secondly, it
defines whether the main script "server.cgi" is
already started by
checking a "pid" file and run
"server.cgi" it if necessary.

The server part "server.cgi" writes its pid into
"pid" file when it
starts, does all the job and writes '0' into "pid"
at exit.
Also "server.cgi" exits if there is no socket
connection in 15 seconds.

The problem is that sometimes it works and sometimes it
doesn't. And I
don't know why. I suppose that maybe something is wrong with
starting
"server.cgi" from within "start.cgi"
though I'm not sure. 

Any ideas about what can be wrong here or any better ways of
making
the whole server part will be very appreciated.


start.cgi code
--------------
#!/usr/bin/perl -w
open(PID, "< pid") || die "Can't open PID
file: $!";
$pid = <PID>;
close PID;

if(defined $pid){
	print "Location: http://www/game/flas
h.html" nn";
	if($pid==0){
		open(TST, "> tst") || die "Can't open
PID file: $!";
		print TST "start";
		close TST;
		system('/var/www/cgi-bin/server.cgi &');
	}
}


server.cgi code
--------------
#!/usr/bin/perl -w

...

open(PID, "> pid") || die "Can't open PID
file: $!";
print PID $$;
close PID;

...

eval {

local $SIG = sub {
 print "alarmedn";
 die "no sockets allowed"; 
 }; 
alarm 15;

... main part of code here

};

if ($ =~ /no sockets allowed/) { 
	open(PID, "> pid") || die "Can't open PID
file: $!";
	print PID '0';
	close PID;
	print "alarm dying...n";
	exit 0;
}
...




Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )