Skip to content
Advertisement

How to run multiple Go lang http Servers at the same time and test them using command line?

EDIT: My aim was to run multiple Go HTTP Servers at the same time. I was facing some issues while accessing the Go HTTP server running on multiple ports while using Nginx reverse proxy.

Finally, this is the code that I used to run multiple servers.

JavaScript

Few newbie mistakes I was making:

  1. ping http://localhost:9000 — As mentioned, ping is used for host not a web address. Use wget http://localhost:9000 instead. Thanks for others for correcting it.
  2. Ending SSH session while running the application on server — Once you close your session, it will also shut down the application.
  3. Use of Ctrl + Z — If you are using single terminal window and you will use Ctrl + Z, it will pause the program and you will face issues while accessing the servers

I hope it will help newbie Go lang programmers like me.

Advertisement

Answer

The classic ping does not work for testing TCP ports, just hosts (see https://serverfault.com/questions/309357/ping-a-specific-port). I’ve seen many frameworks provide a “ping” option to test if the server is alive, may be this is the source of the mistake.

I like to use netcat:

JavaScript

You may have to install it with sudo yum install netcat or sudo apt-get install netcat (respectively for RPM and DEB based distros).

Advertisement