1

Specifically, I have a Windows server (Windows 7), but the netstat -an command only shows whether ports are TCP or UDP. I thought these were the only kinds of ports, but node.js seems to distinguish between HTTP ports and TCP ports (example at bottom of linked page). I'm currently using node.js in a program that will run on my server, and it opens HTTP ports by default. These appear as TCP ports under netstat -an.

Is there a command line trick for distinguishing whether an open port on this server is HTTP or TCP? I make requests to my Information Technology office about ports that I need on this server, and they need to know whether these ports will be TCP, UDP, etc.

If necessary to use a remote client, I have a Mac that can do the job.

7
  • 5
    You're misunderstanding sockets. HTTP is just a text protocol to that you can send over a TCP port.
    – SLaks
    Jul 25, 2014 at 21:10
  • That's what I thought. So this is why I'm really confused: I can make successful connections with the server when I run a Java hello world TCP server. But when node.js makes an "HTTP" server, I can't make a successful connection, even though netstat shows both to be TCP.
    – Matt
    Jul 25, 2014 at 21:13
  • @user262504: Why not? What happens? What error do you get?
    – SLaks
    Jul 25, 2014 at 21:18
  • @SLaks: I used telnet to connect to the Windows machine remotely. However, when I run the server-side program on my local machine on port 9005, telnet localhost 9005 works fine. When I try telnet [Windows hostname] [my valid port], no connection is made; I get a timeout.
    – Matt
    Jul 25, 2014 at 21:32
  • I highly don't think you can telnet into a web/application server. You can send a request to the web server and receive a response, but you can't telnet or ssh to it (if I understand your earlier comments). Jul 25, 2014 at 21:48

2 Answers 2

3

All HTTP traffic is transmitted over TCP Ports. I think what may be causing some confusion is that the first node.js example uses the http module and the second example uses the net module.

The http module is built on top of the net module (which handles the TCP layer underlying HTTP).

Refer to: nodejs - net or http module

EDIT:

Only one process can bind to a port. If you're having difficulties connecting, shut down any other applications that may be using the same port, such as your Java Hello World server. Run netstat -an to make sure you don't see the port listed that you're trying to listen on in you node.js TCP server (port 1337) in the example. If nothing is listening on the port, fire up your node.js TCP server and run netstat -an again to make sure it's actually listening on the intended port.

Another suggestion - temporarily turn off the software firewall then use the telnet client on the local server to attempt to connect to the port using the command telnet 127.0.0.1 1337 (replace 1337 with your port) from the command prompt. This will eliminate any network devices such as firewalls between the client (telnet in this case) and the server. If the screen goes blank, you've connected. If you get the message Could not open connection to the host, on port then it's still not listening on the TCP Port. If you can connect locally from Telnet but you cannot connect remotely then there is something blocking your connection.

1
  • This was a helpful intermediate solution to my larger problem. I don't think it had to do with TCP/HTTP (since HTTP is transmitted over TCP). Apparently, my node.js program only works correctly when installed on my Desktop, and not from the other folder I stored it in (C:\server). Weird...
    – Matt
    Aug 20, 2014 at 12:46
3

HTTP is an application protocol. Its definition presumes an underlying and reliable transport layer protocol. The transmission Control Protocol is commonly used. However HTTP can use unreliable protocols too (example SSDP).

Now to answer to your question:

  • netstat -lt : List TCP Listening Ports
  • netstat -lu : List UDP Listening Ports

If you want to know wether a TCP Port is running HTTP or not, you can check the standard port on HTTP (grep :80). The standard HTTP port is 80. The standard HTTPS port is 443.

2
  • 2
    Or port 443 for HTTPS. Jul 26, 2014 at 0:45
  • Netstat only tells you what ports are open, not how those ports are being used. The fact that port 80 is in use does not guarantee that HTTP is being used. Sometimes apps use port 80 to get through restrictive firewalls. Sometimes HTTP is used on port 8080 on systems that require admin rights to use pprt 80. The only way to know for sure if HTTP is being used is to sniff the network traffic and see what protocol data is actually being transmitted over a given port. Nov 22, 2014 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.