Bottom Page

Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 tcp server/client port connection issue
#1
Hi everyone,
I have quite a simple problem -
please look at my code snippet, this is my simple server:
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()
when it runs, it outputs just 'localhost'.
Next, this is the client on the same machine:
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()
            
When it starts after the server I get the same error:
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.
Quote
#2
Does replacing 'localhost' with '127.0.0.1' change anything?
Quote
#3
No, it doesn't.
It looks like the windows has its own shadow proxy server
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Slow websockets server -> client pattagghiu 0 166 Sep-17-2019, 09:28 AM
Last Post: pattagghiu
  Chat (Client-Server) andresdrr 3 303 Aug-26-2019, 02:01 PM
Last Post: ThomasL
  Python server(Django web site)/client(Python app) connection Junior_Pythoneer 5 383 Jul-05-2019, 05:41 PM
Last Post: noisefloor
  Issue: Script from jumpserver to another server to target device? searching1 0 332 May-29-2019, 03:43 AM
Last Post: searching1
  How to combine data taken from server between client and GUI? bescf 9 802 Apr-02-2019, 11:48 AM
Last Post: bescf
  Multi connection socket server help! MuntyScruntfundle 0 425 Feb-19-2019, 12:03 PM
Last Post: MuntyScruntfundle
  Send data BMP180 between client and server trought module socket smalhao 0 744 Jul-30-2018, 12:56 PM
Last Post: smalhao
  Sending/Receiving Multiple Message from Server or Client Lyperion 0 1,258 Jul-30-2018, 07:52 AM
Last Post: Lyperion
  Need help to make a server/client for DNS Eddie05 1 928 Jun-12-2018, 10:04 AM
Last Post: j.crater
  WebRTC connection from the server Borisko 1 1,724 May-20-2018, 10:15 AM
Last Post: Borisko

Forum Jump:


Users browsing this thread: 1 Guest(s)