Sep-01-2018, 02:10 PM
Hi everyone,
I have quite a simple problem -
please look at my code snippet, this is my simple server:
when it runs, it outputs just 'localhost'.
Next, this is the client on the same machine:
When it starts after the server I get the same error:
-----------------------------------------------------local port-------------remote port------------------------
pythonw.exe--5620----TCP----127.0.0.1-----10137----0.0.0.0.0---------------------LISTENING
pythonw.exe--2960----TCP----127.0.0.1-----2222-----0.0.0.0.0---------------------LISTENING
pythonw.exe--5980----TCP----127.0.0.1-----10128----127.0.0.1------10125-------ESTABLISHED
pythonw.exe--5620----TCP----127.0.0.1-----10125----127.0.0.1-------10128------ESTABLISHED
If I start firefox on localhost:2222 it connects to the server and the server outputs:
Notice that the remote port raddr is not 2222. Why?
What is redirecting port from 2222 to another?
How make my client connect to the server at the same port 2222?
I have windows 8, the same machine, the firewall is off, the router is off, no internet, no wifi while I carry out this experiment.
I have quite a simple problem -
please look at my code snippet, this is my simple server:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import socket def Main(): host = 'localhost' port = 2222 s = socket.socket() print (host) s.bind((host,port)) s.listen( 1 ) c,addr = s.accept() print ( "Connection from: " + str (addr) + "\n" + str (c)) s.close() if __name__ = = '__main__' : Main() |
Next, this is the client on the same machine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import socket def Main(): host = 'localhost' port = 2222 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host,port)) s.close() if __name__ = = '__main__' : Main() |
Error:============== RESTART: E:/Progs/Python 3.6.3/tcpServerTest.py ==============
localhost
============== RESTART: E:/Progs/Python 3.6.3/tcpClientTest.py ==============
Traceback (most recent call last):
File "E:/Progs/Python 3.6.3/tcpClientTest.py", line 15, in <module>
Main()
File "E:/Progs/Python 3.6.3/tcpClientTest.py", line 9, in Main
s.connect((host,port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
>>>
Well then, while I run TcpView from sysinternals I see four rows and somehow port 2222 is redirected(?) to another port:-----------------------------------------------------local port-------------remote port------------------------
pythonw.exe--5620----TCP----127.0.0.1-----10137----0.0.0.0.0---------------------LISTENING
pythonw.exe--2960----TCP----127.0.0.1-----2222-----0.0.0.0.0---------------------LISTENING
pythonw.exe--5980----TCP----127.0.0.1-----10128----127.0.0.1------10125-------ESTABLISHED
pythonw.exe--5620----TCP----127.0.0.1-----10125----127.0.0.1-------10128------ESTABLISHED
If I start firefox on localhost:2222 it connects to the server and the server outputs:
Output:============== RESTART: E:/Progs/Python 3.6.3/tcpServerTest.py ==============
localhost
Connection from: ('127.0.0.1', 10152)
<socket.socket fd=444, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 2222), raddr=('127.0.0.1', 10152)>
>>>
Notice that the remote port raddr is not 2222. Why?
What is redirecting port from 2222 to another?
How make my client connect to the server at the same port 2222?
I have windows 8, the same machine, the firewall is off, the router is off, no internet, no wifi while I carry out this experiment.