How to rewrite the TCP destination port during the TCP connection on Windows? - windows

I have a client which is intended to connect to a server. For the client, the remote TCP port number is fixed(i.e. 102). I can NOT change it(while I can change the remote IP address). However, the TCP Port number the server is listening on is fixed as well(i.e. 1024) and I can NOT change it too. These two port numbers are different. I want to make the client connect to the server smoothly.
At the first, I had a idea that I setup a proxy listening on localhost:102 and the client connect to 127.0.0.1:102. Then this proxy redirect these TCP traffic to the real address RemoteServerIP:1024. But I found on my windows, there was already a process which is listening on 0.0.0.0:102 and I can NOT change its listening port. So this idea can NOT work.
Thank you very much.

if you cannot do it on the same windows machine running client, why not try to do it on another (linux maybe) machine?

Related

Command to check if can access to Websocket address & port

I'm looking for a command like:
ping google.com
But I also want to use the port, like google.com:8080
I want to know if a client can connect to my servers socket listener at a certain port.
My core problem is, 100% of users are able to connect to my websocket port at 8080, but only single digit x% are able to connect to websocket port at 2053. This is independent of device. After research I've found out that some ISPs might be blocking this port.

How do I check whether an open port is TCP or HTTP?

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.
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.
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.

Can I establish more than 1 TCP connections to same server on same port from same single client? Specifically to port 445

Can I establish more than 1 TCP connections to same server on same port ?
For example :
Connection 1: machine A to Machine B on port 445
Connection 2: machine A to Machine B on port 445
Without terminating previously established connection 1.
If yes, do i need to do any setting to enable such scenario ?
Yes, you can. Without any special setting.
That's exactly what happens when you start, let's say Internet Explorer and Mozilla Firefox and navigate to the same site with both.
Behind the scene to connect to the server, machine A opens a socket using whatever port number and tries to connect to machine B port 445. Machine B, who was listening on port 445 can accept this incoming connection, and uses another socket using whatever other port number to connect it to. In the end, the actual TCP connection is established between whatever port en machine A and whatever port on machine B. On machine B, port 445 is left for listening only (and can accept other connections).
Yes you can, a TCP/IP session is identified by the following 5-tuple:
(src-ip, src-port, dst-ip, dst-port, protocol).
In your case, 4 of the 5 values have to be the same: src-ip (A), dst-ip (B), dst-port (445), protocol (tcp). As such, the src-port still gives you a degree of freedom, by variating this, you can set up multiple sessions. This is what should happen by default, your OS will select a new, unique source port for each connection to the same server.
TCP/IP standard supports this with ephemeral ports. You connect to fixed port on server side, but port on client side is not under your control. TCP/IP stack will choose client port, and connection is then defined and distinguished from other connections with 4 bits of information: client IP address, client port, server IP address, and server port.

Cannot connect to TCP Socket Listening on user PC (Static IP)

I am using Boost asio in Visual C++. I am trying to connect to a static IP which listens TCP on port 1222. unfortunately i can only connect with Lan and cannot connect from another Lan to the TCP listening PC(203.143..).
It connects perfectly with the EC2 server. Is it something to do with firewall. but when i run the app it ask for the user to allow firewall for the specific port. I can post my code but i guess it's not something to with the code.
Usually a firewall on the server side (the PC you are trying to connect to) have to be configured to allow incoming connections.
Firewall on your side should be OK, it usually allows any type of outgoing connections.
I don't know what you meant by "the app ask for the user to allow firewall for the specific port" (clarify).

Creating a local server visible through firewalls

I have a local server written in C++ listening to inbound TCP connects using plain socket ::accept() and UDP recvfrom(). I have two problems with this that I wish to solve:
Can I programatically make Windows let me open the accept socket without it automatically being blocked by the Windows (software) firewall?
Are there any ports I can use that will allow my packets to pass through both Windows firewall and external firewall? Port 80 is often taken by things like Skype, but are there others? Will most external firewalls typically by default allow incoming UDP and TCP connects on port 80?
Thanks!
In general, network routers need Port Forwardng enabled for the listening port, and firewalls need the listening port opened. If you are using a uPNP-enabled firewall/router, then you can dynamically set up those settings programmmably via the uPNP API. But more times than not, uPNP is either disabled or unavailable, requiring manual settings by the firewll/router admin.

Resources