c# - TcpListener and TcpClient sharing local port -


i have 2 instances of same application, on different machines, should talk each other, no 1 typical server or client.

both instances of application has tcplistener, local port = 8000.

one application instance (call "a") creates tcpclient. now, client can't have local port = 8000, or constructor throws socket exception "only 1 usage of each socket address (protocol/network address/port) permitted".

so, create first client random local port, , run connect() connect other application instance "b".

"b" accepts connection using tcplistener.accepttcpclient(), returns tcpclient can used communicate "a". though, tcpclient has same ip , port tcplistener!? how possible, when not use same port when created tcpclient manually on "a"? them use same port listener, on both machines...

so, how can create tcpclient on "a" same port tcplistener?

i think might not understand address port client server architecture.

tcplistener listening connection on address , port. after connection established can use "socket" receive , send messages client , server both.

example:

0.0.0.1 machine a.

0.0.0.2 machine b.

you can put tcplistener listening on port 8000 on machine a. when tcpclient on machine b make try connect machine on port 8000 tcpclient on machine b generated (by os) port.

and have connection

0.0.0.1:8000 -> 0.0.0.2:3587(generated port) - dont need worry client listening port.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -