
Made a client-server application in C # using the Socket class. If I start the Server and Client on the 1st machine, everything works, the Client sees the Server. (Server IP: port - 127.0.0.1:8005, Client has the same one). If on different machines (for the Server, the IP: port is 127.0.0.1:8005, the Client has the ip-address of the local server, the port is the same, for example, 192.168.1.33:8005). The client does not see the server. Tried: - 2 WinXP on virtual machines (ping is) -> see photo - WinXP and Win7 on WiFi network via router (port opened on router, ping is).
I have not tried it yet: - connect physical machines with a cable.
Question: Maybe there is some kind of nuance (in the code or when setting up the network) when connecting to 2 machines to perform the Client-server connection, unlike him on the 1st machine?
The connection code is attached below:
// Server namespace ServerSocket {class Program {static int port = 8005; static string localHost = "127.0.0.1";
static void Main(string[] args) { IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(localHost), port); listenSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp); try { listenSocket.Bind(ipPoint); listenSocket.Listen(clientsLimitForListener); Console.WriteLine("Server was started. Waiting for connections...\n"); . . .
// Client namespace ClientSocket {class Program {static int port = 8005; static string address = "192.168.1.33";
static void Main(string[] args) { try { Socket socket = null; Console.WriteLine("CHAT\n"); Console.Write("Input your name: ") string name = Console.ReadLine().Trim(); Console.WriteLine("\nType message and press Enter.\n"); IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(address), port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipPoint); while (true) { . . .
localHost = "127.0.0.1"So you only have it and the local host is listening, so the rest of the clients from the network cannot connect. - Gennady P