Bottom Page

Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 tcp server/client port connection issue
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()

    c,addr = s.accept()
    print("Connection from: " + str(addr) + "\n" + str(c))


if __name__ == '__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)
if __name__ == '__main__':
When it starts after the server I get the same error:
============== RESTART: E:/Progs/Python 3.6.3/ ============== localhost ============== RESTART: E:/Progs/Python 3.6.3/ ============== Traceback (most recent call last): File "E:/Progs/Python 3.6.3/", line 15, in <module> Main() File "E:/Progs/Python 3.6.3/", 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------------------------

If I start firefox on localhost:2222 it connects to the server and the server outputs:
============== RESTART: E:/Progs/Python 3.6.3/ ============== localhost Connection from: ('', 10152) <socket.socket fd=444, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('', 2222), raddr=('', 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.
Does replacing 'localhost' with '' change anything?
No, it doesn't.
It looks like the windows has its own shadow proxy server

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Get trunk port Remiix93 1 1,287 Jul-11-2019, 10:39 AM
Last Post: Larz60+
  Python server(Django web site)/client(Python app) connection Junior_Pythoneer 5 247 Jul-05-2019, 05:41 PM
Last Post: noisefloor
  Issue: Script from jumpserver to another server to target device? searching1 0 232 May-29-2019, 03:43 AM
Last Post: searching1
  Make sockest keep connection LavaCreeperKing 3 262 May-21-2019, 05:05 AM
Last Post: heiner55
  How to combine data taken from server between client and GUI? bescf 9 578 Apr-02-2019, 11:48 AM
Last Post: bescf
  Graphql subscriptions client Edoar 0 239 Mar-11-2019, 04:13 PM
Last Post: Edoar
  How to open port 8080 in CentOS 7 nikos 0 490 Mar-02-2019, 03:02 PM
Last Post: nikos
  Multi connection socket server help! MuntyScruntfundle 0 327 Feb-19-2019, 12:03 PM
Last Post: MuntyScruntfundle
  TCP/IP client script help Rehan11 2 542 Jan-15-2019, 06:48 AM
Last Post: Rehan11
  recive post request from client(browser) python sockets kunz 1 588 Dec-13-2018, 12:53 AM
Last Post: kunz

Forum Jump:

Users browsing this thread: 1 Guest(s)