I have two Windows Forms applications, one acting as a server (i.e. Winform: server role ), and the other acting as a client (i.e. Winform: client role >). There are 6 PCs on my local network, and these PCs are connected to each other via an 8-port switch, and each PC has more than one LAN card.
There is one computer running [Winform: server role], and the other five - the [Winform: client] role. In [Winform: Server role], I use the following code to get the local IP address and port number, and [Winform: Server role] will listen for all incoming TCP requests according to this automatically assigned IP address and port number.
Dim Listener As System.Net.Sockets.TcpListener Dim Client As New System.Net.Sockets.TcpClient Dim Message As String = "" Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, 0) Listener.Start() End Sub
How does everyone [Winform: Client role] know my [Winform: Server role] IP address and port number at runtime?
I need to clarify my intention. My current approach to my intention may be wrong. I am trying to create a "zero client-server network configuration" and it is plug and play. The server will know where the client is and vice versa. I know that there is a program (that is, MaxiVista) did it this way.
MaxiVista has two applications, that is, a server and a client. Users only need to run the server application on the PC designated as the server role and run the client application on another PC designated as a client. Then the server will be able to find all executable clients on the same local network.
That is my intention. Plug and play with a “zero client-server network configuration” within the same local network.
user774411
source share