New topic: How to run compiled app from same PC as developed?
<http://forums.realsoftware.com/viewtopic.php?t=38288> Page 1 of 2 [ 19 posts ] Go to page 1, 2 Next Previous topic | Next topic Author Message tseyfarth Post subject: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 3:08 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 Hello all. I want to try running the compiled application on my notebook computer. This is the same as the one that is being used to develop. It has Apache installed as well as the PostgreSQL database. I have compiled as a CGI 2011R1, and placed the contents of the compiler out put into the CGI-Bin folder inside of the Apache folder. I am at a loss as to how to get the browser to open/start the application. Can anyone tell me how to do this? Thank you Tim Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 3:15 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 Aparantly there is also IIS 7.0 installed on this machine too. The debugger must be using this, since it points to http://127.0.0.1:34993/frmMain Top charonn0 Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 3:44 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 385 Location: San Francisco, CA, USA Whichever server platform you use, the URL will always start with http://127.0.0.1 since that's the IP address that always refers to the local machine. Port number and path may vary. _________________ Boredom Software Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 5:13 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 OK, so how do I get it to run? IIS is trying to run it, so I put the files into the inet folder. But I would rather have only Apache try to run it. So right now neither will run it. Ideas anyone? Top timhare Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 5:23 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 9547 Location: Portland, OR USA Find out which port Apache is listening to and use that port. If they're both running, then they're either competing for the same port (which is a config error) or each is configured for a specific port, typically 80 or 8080. Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 5:40 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 Apache is set to 8088. Tomcat is NOT running. Is that necessary? Tim Top swort Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 6:55 pm Joined: Mon May 31, 2010 5:35 am Posts: 840 try: [url]http://localhost/[appname].cgi[/url] replace [appname] with your application name. _________________ SWORTâ¢, it stands for Secure Web Object Realtime Transfer⢠- Windows Vista AND Linux Ubuntu 10.04 LTS - REAL Studio Enterprise(latest) and WEB Edition(latest) - REAL SQL Server 2009 For Dutch User Groups ask me to enter! Top swort Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 6:56 pm Joined: Mon May 31, 2010 5:35 am Posts: 840 Edit doesnt work for the forum but i meant this: http://localhost/[appname].cgi _________________ SWORTâ¢, it stands for Secure Web Object Realtime Transfer⢠- Windows Vista AND Linux Ubuntu 10.04 LTS - REAL Studio Enterprise(latest) and WEB Edition(latest) - REAL SQL Server 2009 For Dutch User Groups ask me to enter! Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 7:32 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 Hi Swort.... Thanks for your reply! Without the port, it brings up an IIS error page. With the port, it brings up the cgi script. Tim Top swort Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 8:39 pm Joined: Mon May 31, 2010 5:35 am Posts: 840 tseyfarth wrote:Hi Swort.... Thanks for your reply! Without the port, it brings up an IIS error page. With the port, it brings up the cgi script. Tim ok then your port is different then the default server port? _________________ SWORTâ¢, it stands for Secure Web Object Realtime Transfer⢠- Windows Vista AND Linux Ubuntu 10.04 LTS - REAL Studio Enterprise(latest) and WEB Edition(latest) - REAL SQL Server 2009 For Dutch User Groups ask me to enter! Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Wed Mar 23, 2011 11:18 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 I checked it again, I was referencing a document that I had, but was able to find it by trying both port 8088 and 8080. I had set it to 8088 since something else wanted 8080 at one point. But since then the server was re-installed. Anyway it is on 8080. This just shows the cgi script. http://localhost:8080/axcysembedded.cgi Tim Top swort Post subject: Re: How to run compiled app from same PC as developed?Posted: Thu Mar 24, 2011 6:22 am Joined: Mon May 31, 2010 5:35 am Posts: 840 tseyfarth wrote:I checked it again, I was referencing a document that I had, but was able to find it by trying both port 8088 and 8080. I had set it to 8088 since something else wanted 8080 at one point. But since then the server was re-installed. Anyway it is on 8080. This just shows the cgi script. http://localhost:8080/axcysembedded.cgi Tim only the raw script? _________________ SWORTâ¢, it stands for Secure Web Object Realtime Transfer⢠- Windows Vista AND Linux Ubuntu 10.04 LTS - REAL Studio Enterprise(latest) and WEB Edition(latest) - REAL SQL Server 2009 For Dutch User Groups ask me to enter! Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Thu Mar 24, 2011 1:57 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 Yes, just the script http://localhost:8080/axcysembedded.cgi #!/usr/bin/perl use constant TYPE_VALUE => 0; use constant TYPE_STRUCT => 1; use constant MAX_CHUNK => 65530; use strict; my $socket_available = eval "use IO::Socket; 1"; if ($socket_available != 1) { handle_error("This script requires the IO::Socket module."); exit; } my $request; my $as_fcgi = 0; my %config; load_config(); my $app_port = $config{port}; if ($config{auto_port} eq "1") { $app_port = pick_port($config{port}); if ($config{port} != $app_port) { $config{port} = $app_port; write_config(); } } my $fcgi_available = eval "use FCGI; 1"; my $iohandle_available = 0; my $modern_threads_available = 0; my $old_threads_available = 0; my $request; if ($fcgi_available == 1) { $request = FCGI::Request(); $as_fcgi = $request->IsFastCGI(); if ($as_fcgi == 1) { $iohandle_available = eval "use IO::Handle; 1"; $modern_threads_available = eval "use threads('yield','stack_size' => 64 * 4096,'exit' => 'threads_only'); 1"; if ($modern_threads_available != 1) { $old_threads_available = eval "use Thread; 1"; } } } else { $as_fcgi = 0; } my $threads_available = ((($modern_threads_available) || ($old_threads_available)) && ($iohandle_available)); if ($as_fcgi == 1) { if ($threads_available == 1) { my $t, my $thr; for ($t = 1; $t < $config{thread_count}; $t++) { if ($modern_threads_available) { $thr = threads->create('fastcgi_thread'); } else { $thr = new Thread \&fastcgi_thread; } $thr->detach(); } fastcgi_thread(); } else { while ($request->Accept() >= 0) { print "Content-type: text/plain\n\n"; print "The script '$0' requires threads to operate as a FastCGI. Please ensure the Perl modules 'IO::Handle' and either 'Threads' or 'Thread' are installed."; $request->Flush(); } } } else { cgi_handler(); } exit; sub fastcgi_thread { my %env; my $in = new IO::Handle; my $out = new IO::Handle; my $err = new IO::Handle; my $sock; my $request = FCGI::Request($in, $out, $err, \%env); my $tid; if ($modern_threads_available == 1) { $tid = threads->tid(); } else { $tid = Thread->self->tid; } while ($request->Accept() >= 0) { if ($app_port <= 0) { handle_error("Unable to find usable port. Please check firewall settings and try again.",$out); $request->Flush(); next; } if (!$sock) { $sock = create_socket($app_port); } if ((!$sock) || (test_connection($sock) == 0)) { my $launch = launch($app_port); if ($launch == 1) { $sock = create_socket($app_port); if (!$sock) { handle_error("Application launched, but unable to connect using port $app_port.",$out); $request->Flush(); next; } } else { handle_error("Unable to launch application on port $app_port: $launch",$out); $request->Flush(); next; } } my $body = ''; foreach my $key (sort keys(%env)) { $body .= create_value(TYPE_VALUE,$key); $body .= create_value(TYPE_VALUE,$env{$key}); } my $sin = ''; while (my $line = <$in>) { $sin .= $line; } $body .= create_value(TYPE_VALUE,"STDIN"); $body .= create_value(TYPE_VALUE,$sin); $body = create_value(TYPE_STRUCT,$body); print $sock $body; my $continue = 0; my $loopcount = 0; my $responded = 0; do { my $type, my $length, my $response; $sock->recv($type,1); $sock->recv($length,4); $type = unpack('C',$type); $length = unpack('N',$length); $response = ''; do { my $chunk_size = $length - length($response); if ($chunk_size > MAX_CHUNK) { $chunk_size = MAX_CHUNK; } my $r; $sock->recv($r,$chunk_size); $response = $response . $r; } until (length($response) == $length); if ($response eq 'keepalive') { $continue = 1; $loopcount++; if ($loopcount == 1) { print $out "X-RSWE-Keepalive: "; } print $out "."; } else { $continue = 0; if ($loopcount > 0) { print $out "\n"; } print $out $response; $responded = 1; } $request->Flush(); } until ($continue == 0); if ($responded == 0) { handle_error("Did not receive response from application",$out); $request->Flush(); next; } } close($sock); } sub cgi_handler { my $type, my $length, my $response; my $responded = 0; my $sock = create_socket($app_port); if (!$sock) { my $launch = launch($app_port); if ($launch == 1) { $sock = create_socket($app_port); if (!$sock) { handle_error("Application launched, but unable to connect using port $app_port."); exit; } } else { handle_error("Unable to launch application on port $app_port: $launch"); exit; } } my $body = ""; foreach my $key (sort keys(%ENV)) { $body .= create_value(TYPE_VALUE,$key); $body .= create_value(TYPE_VALUE,$ENV{$key}); } my $sin = ""; while (my $line = <STDIN>) { $sin .= $line; } $body .= create_value(TYPE_VALUE,"STDIN"); $body .= create_value(TYPE_VALUE,$sin); $body = create_value(TYPE_STRUCT,$body); print $sock $body; my $continue = 0; my $loopcount = 0; do { $sock->recv($type,1); $sock->recv($length,4); $type = unpack('C',$type); $length = unpack('N',$length); $response = ''; do { my $chunk_size = $length - length($response); if ($chunk_size > MAX_CHUNK) { $chunk_size = MAX_CHUNK; } my $r; $sock->recv($r,$chunk_size); $response = $response . $r; } until (length($response) == $length); if ($response eq 'keepalive') { $continue = 1; $loopcount++; } else { $continue = 0; print STDOUT $response; $responded = 1; } } until ($continue == 0); close($sock); if ($responded == 0) { handle_error('Did not receive response from app'); exit; } } sub create_value { my $type = @_[0]; my $value = @_[1]; my $len = length($value); my $t = pack('C',$type); my $l = pack('N',$len); return $t . $l . $value; } sub create_socket { my $port = @_[0]; my $sock = new IO::Socket::INET( PeerAddr => '127.0.0.1', PeerPort => $port, Proto => 'tcp' ); return $sock; } sub launch { my $port = @_[0]; my $is_windows = ($^O eq 'MSWin32'); my $appname = $config{appname}; if ($is_windows == 1) { system("\"$appname\" --port=$port") == 0 or return "$!"; } else { my $appname_escaped = shell_escape($appname); system("./$appname_escaped --port=$port") == 0 or return "$!"; } return 1; } sub pick_port { my $port; my $sock; my $attempts = 0; $port = @_[0]; while ($attempts < 3) { if ($port > 0) { $sock = new IO::Socket::INET ( LocalPort => $port, Proto => 'tcp', Listen => 1, Reuse => 1 ); if ($sock) { close($sock); return $port; } $sock = new IO::Socket::INET( PeerAddr => '127.0.0.1', PeerPort => $port, Proto => 'tcp' ); if ($sock) { if (test_connection($sock)) { close($sock); return $port; } } $attempts++; } $port = 1025 + int(rand(64510)); } return -1; } sub test_connection { my $sock = @_[0]; my $ping = create_value(TYPE_VALUE,"1"); print $sock $ping; my $pong; $sock->recv($pong,6); if (length($pong) != 6) { return 0; } else { return 1; } } sub load_config { my $opened = open(CONFIG,"<config.cfg"); if (!$opened) { handle_error("Cannot read config.cfg: $!"); exit; } %config = (); my $key, my $value; while (my $line = <CONFIG>) { $line = trim($line); ($key,$value) = split("=",$line,2); $key = lc($key); $config{$key} = $value; } close(FILE); } sub write_config { my $opened = open(CONFIG, ">config.cfg"); if (!$opened) { handle_error("Cannot write to config. $!"); exit; } foreach my $key (sort keys(%config)) { my $value = $config{$key}; $key = uc($key); print CONFIG "$key=$value\n"; } close(CONFIG); } sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } sub handle_error { my $error = @_[0]; my $stream = @_[1]; if (!$stream) { $stream = *STDOUT; } print $stream "Status: 200 OK\n"; print $stream "Content-type: text/plain\n\n"; print $stream "$error\n"; } sub shell_escape { @_[0] =~ s/([\s;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g; return @_[0]; } http://localhost:8080/axcysembedded Not Found The requested URL /axcysembedded was not found on this server. Top swort Post subject: Re: How to run compiled app from same PC as developed?Posted: Thu Mar 24, 2011 3:08 pm Joined: Mon May 31, 2010 5:35 am Posts: 840 Where is the extention after link? eg: .cgi _________________ SWORTâ¢, it stands for Secure Web Object Realtime Transfer⢠- Windows Vista AND Linux Ubuntu 10.04 LTS - REAL Studio Enterprise(latest) and WEB Edition(latest) - REAL SQL Server 2009 For Dutch User Groups ask me to enter! Top tseyfarth Post subject: Re: How to run compiled app from same PC as developed?Posted: Thu Mar 24, 2011 6:53 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 199 I tried both .cgi and none. I put it in at the very top of my last post. What follows is the cgi script. When I do it without the .cgi, I get the msg not found on this server (this is at the bottom of the post). Tim Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 2 [ 19 posts ] Go to page 1, 2 Next
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
