B4J Question Killing a server, and refreshing

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

This problem has been recurring for a while, and I'm not sure of the cause.

Using the following very basic code to start a server,

B4X:
        Log( "Start" )
	srver.Initialize( "srvr" )
	' srver.Port = 12612
	srver.Port = 8888

	srver.Start
	
	StartMessageLoop
	
	Log( "End" )


, the index file at ..\objects\www gets loaded appropriately, the first time.

So if we start using the port 12612 that's commented above, the index file is displayed.

But if we Kill the server process inside B4J, and then regenerate the index.html file with changes and restart the server, the changes aren't reflected on the screen.

In fact, even if we kill the server and DON'T restart it, the original index.html file is displayed. I've tried clearing the Chrome cache, but to no avail. Chrome apparently thinks the server is still running , and maybe Chrome is right.

If we change the port from 12612 to 8888, then the changes DO reflect. But if we make changes after running 8888 the first time, they don't show up after refreshing, or after restarting the server.

What am I missing? Is there some other way to stop the server during development, other than Kill Process?
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Check out the two step process suggested in this forum

https://superuser.com/questions/215351/how-do-i-kill-a-process-that-is-dead-but-listening

step 1. Find PID using command window => C:\Users\username>netstat -o -n -a | findstr 12612
step 2. Kill PID => C:\Users\username>taskkill /F /PID 3116 (the number of whatever PID you found)

If this doesn't work, go to above link and read more.

Bill, thanks but this isn't the problem. The server isn't really active. The same problem persists, even after a reboot. And it happens on at least two PCs.

Neither port is returned from Netstat. Also, I use a utility called CurrPort https://www.nirsoft.net/utils/cports.html, and it doesn't show any of these ports after the process is killed in B4J.

It's another issue, that's probably unrelated to B4J. I'm just asking it here, in case someone has experienced similar symptoms.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
In fact, even if we kill the server and DON'T restart it, the original index.html file is displayed. I've tried clearing the Chrome cache, but to no avail. Chrome apparently thinks the server is still running , and maybe Chrome is right
1) You could try using another browser. This way you can double check chrome's behavior. You could even use wget (Windows and/or Linux) and try to pull the page from the command line. I don't think wget caches anything.
2) How are you hosting your server? Make sure there is not a proxy/load balancer in front of your server that keeps serving stale pages.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I just tried to replicate what you found and it works fine with Chrome and Microsoft Edge.
Start server, get index with Chrome, Kill Server, modify index, start server, refresh Chrome => shows modified index.
So you have a puzzle for sure.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
1) You could try using another browser. This way you can double check chrome's behavior. You could even use wget (Windows and/or Linux) and try to pull the page from the command line. I don't think wget caches anything.
2) How are you hosting your server? Make sure there is not a proxy/load balancer in front of your server that keeps serving stale pages.

I think I need to try this, in a totally different environment. Same symptoms, in both Chrome and IE.

I'll try this from the hotel, and then from home later in the week.

Thanks, OliverA and Bill.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Are you refreshing the page in chrome after you edit the index file ?

If you edit the index.html you do not need to stop the server, when the page is refreshed the new page will be served to the browser.
 
Last edited:
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Are you refreshing the page in chrome after you edit the index file ?

If you edit the index.html you do not need to stop the server, when the page is refreshed the new page will be served to the browser.

Not only am I refreshing it, but after the problem continues, I tried rebooting.

Even WITHOUT the server running, after rebooting, localhost:12612 and localhost:8888 returns the same index file with the same title as it did before. Since the server isn't active, it shouldn't be returning anything.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
So you are running the web browser on the same machine that is running the B4J application?

Yes. I've done it before, and never had this problem. Previously, simply killing the process would clear everything. You could make changes, restart the server, and all the changes would be reflected.

This is localhost, I'm not having a problem with external servers.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
So all Java instances are terminated in Task Manager? You have no instance of Apache or any other web server running on the machine? No strange plug-ins? Chrome web server plugin?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Nothing weird in the host file (c:\windows\system32\drivers\etc\hosts)? No weird proxy settings under Control Panel->Internet Properties->Connections->LAN settings->Proxy server?
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
If you edit the webpage and it still shows the old webpage try force refreshing the page (Ctrl+F5) in the browser. It might be serving the pages from the cache and not requesting the server for the files.

Refreshing the page (F5) most likely is showing the same page. Ctrl+F5 makes the browser fetch the files again from the server.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Even WITHOUT the server running, after rebooting, localhost:12612 and localhost:8888 returns the same index file with the same title as it did before. Since the server isn't active, it shouldn't be returning anything.
This seems very unlikely, unless you are using a service worker (like with BANano with the .UseServiceWorker = true setting). In that case the behavior you describe can happen as such a webapp/website can run without a server.

In chrome press F12 and go the the application tab: check if any service worker is active on one of the ports you use. Also, check the network tab when you press ctrl-F5 to see where it gets its files from.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
OliverA, aaronk, alwaysbusy, thanks.

There seem to be several factors in play. On my personal laptop, that Chrome Server Plugin and others from one of the Banano projects was active. I removed that, and the resulting page reflects the index.html, on port 8888. On port 12612, nothing seems to happen. However, I haven't looked at it in debug mode, yet.

On my office PC, yes - lots of things that could cause this problem.

First, on the office PC, I did the same thing as the Personal Laptop. I removed

Web Server for Chrome
JetBrains IDE Support
Simple Websocket Client

, and Chrome isn't much different. IE seems to be working fine, though.

In debug mode, several candidates for root causes - There is a 404 error in the log, even though it doesn't show up on the web page.

For one thing, the service worker is activated. There's also a missing banano function in there.

The basic problem is that I copied a Banano-generated index and app.js file into the server folders. This is obviously the source of the issue. I'll go ahead and do a cleanup, on the personal laptop, office pc, and home desktop.



Thanks and regards,
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
This seems very unlikely, unless you are using a service worker (like with BANano with the .UseServiceWorker = true setting). In that case the behavior you describe can happen as such a webapp/website can run without a server.

In chrome press F12 and go the the application tab: check if any service worker is active on one of the ports you use. Also, check the network tab when you press ctrl-F5 to see where it gets its files from.

Alain, I've had no luck with this. I cleared the folders out that the server was using.

I regenerated the index, and generated a test.js (in place of app.js), after setting BANano.UseServiceWorker = False.

I opened up the PHP IDE that I use for PHP development, at the office. The first time (under port 8080), it will display the expected page, based on what the Banano module generated.

But after making changes, under the same port (8080, in this case), the original content persists. Viewing it Chrome debug mode, it still thinks there's a service-worker.js, even though the folders were all cleared out.

I've never experienced this before. Clearing the caches have always worked in scenarios similar to this. Is there some command, or something I can do, to totally clear these ghost files for all ports?
 
Upvote 0
Top