V
V
VZVZ2016-02-10 13:37:15
C++ / C#
VZVZ, 2016-02-10 13:37:15

How to connect 2 computers connected to the Internet: on one run one instance of my program, on the other - the other, and so that the instances communicate via TCP?

Having previously worked only with HTTP (a rather high-level and simple protocol), now I am slowly descending deeper, to the level of TCP and rarer protocols based on it.
I'm mainly interested in sniffing and creating bots that imitate clients for existing servers (usually TCP is used by NodeJS servers, there are also XMPP and other fast messaging protocols where TCP + TLS encryption)
But at the same time I decided to deal with the direct purpose of TCP / IP, then there is a direct connection of two computers without a third-party HTTP server (which is the simplest and most stupid solution to such a problem).
So.
I wrote 2 test programs using System.Net.Sockets, one is a server, the other is a client.
The client sends a test packet to the server, the server, upon receiving it, sends a response packet to the client, this is not the point. IP and port are set by the user both at the server and at the client.
Everything works on localhost.
But now I have 2 computers with Windows 8/8.1 (not Server), and it is necessary that the client be on one of them, and the server on the other.
What needs to be done for this?
1) On what IP to start the server, to what IP to connect from the client? What about ports?
2) What where to set up?
3) In general, of course, I would like the computers to not be physically connected in any way, only via the Internet. Moreover, they are not necessarily connected to one point.
Is this possible?
But, if necessary, you can create your own Wi-Fi point / network, you can also connect it with a cable.
What exactly is needed from this?
As for Google, I ask you not to write.
I know how to google, and in parallel with waiting for answers to my question, I will google.
But this is not an easy task, and I do it better than many others. But now I'm in a shitty mood, and to be honest, I don't feel like doing anything at all. But you must.
UPD: Damn-how- everything- difficult - reluctance. Burn it all with fire, I'll take http

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
Larry Underwood, 2016-02-10
@Hydro

1) On what IP to start the server, to what IP to connect from the client? What about ports?
2) What where to set up?
3) In general, of course, I would like the computers to not be physically connected in any way, only via the Internet. Moreover, they are not necessarily connected to one point.

1) If the server machine is not given a dynamic IP from the provider, then everything is simple either on 0.0.0.0 or to the external IP of the server machine to make a binding in the program. If the server machine is behind NAT, then you need to forward ports, as a rule, NAT is enabled on the home router or at the provider. If there is no NAT, then everything is simple, on which port the server opened, you connect to it from the client
2) Check that the server port is not blocked by a firewall / antivirus and that the selected port does not conflict with a predefined value (it is better to choose a port number > 1000) .
3) TCP works on top of IP, and the IP protocol in general isolates us from the concept of "physically connected", at the IP level and above we operate with the abstract concept of "route", and not "twisted pair" or "wifi connection"

A
Anton Ulanov, 2016-02-10
@antonsr98

as an example, the server you have is on ip 192.168.0.101 broadcasts and listens on port 1000, the client is on a PC with ip 192.168.0.102 there is a client that listens and receives packets on port 1000. read about client-server applications

P
Peter, 2016-02-10
@petermzg

You must have a public IP on the server. To obtain it, contact your provider.
Further, if your computer is on the local network (behind a router or server), then through NAT you need to forward the port from the server / router to the computer where the server part of the application is installed.

N
none7, 2016-02-10
@none7

  1. IPAddress.Any any port you want, each network interface has an address, and specify it on the remote machine, or register it in DNS. All system addresses can be obtained via Dns.GetHostAddresses (Dns.GetHostName())
  2. Is that the firewall to configure if enabled
  3. With a computer that has a "white" IPv4 address or an IPv6 address, anyone can request a connection regardless of the network and the distance to that network. In the case of a computer behind NAT, only those on the same network or via UDP + STUN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question