I have two Windows Forms applications, one acts as server (that is, Winform:Server role) and another one as a client (that is, Winform: Client role). In my LAN setup, there are 6 PCs and these PCs connected to each other via a 8-port switch and each PC has more than one LAN card.
There is one PC running [Winform: Server role] and five others running the [Winform: client role]. In [Winform: Server role], I'm using following code to obtain the local IP address and port number and the [Winform: Server role] will listen to all incoming TCP requests according to this auto-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 do all [Winform: Client role] know my [Winform: Server role] IP address and port number at run time?
I need to clarify my intention. My current approach to my intention maybe incorrect. I attempt to create a 'zero configuration client-server networking' and that is plug & play. The server will know where the client and vise versa. I know there is a program (that is, MaxiVista) has done that exactly.
MaxiVista has two applications, that is, server and client. Users only need to execute the server application in PC designated as server role and execute the client application in another PC designated as client role. Then the server will be able to find all executing clients in the same LAN.
My intention is just that. Plug and play 'zero configuration client-server networking' within the same LAN.
The port number is “tacked on” to the end of the IP address, for example, “192.168. 1.67:80” shows both the IP address and port number.
How to find your port number on Windows. Type “Cmd” in the search box. Open Command Prompt. Enter the netstat -a command to see your port numbers.
The IP address refers to the Internet Protocol Address. These basically identify a host present in a network. We use Port numbers for identifying any process/ service present on your system. Bits Used. The size of IPv4 is 4 bytes (32 bits), and that of IPv6 is 16 bytes (128 bits).
IP addresses are assigned to item data ports in the Web Client on an item's page while it is in Edit mode from the Data - Ports tab via a IP Address Assignments dialog.
Well, they don't, really.
You could configure DNS for e.g. yourappserver
to point to your server and then have the clients connect to that, but that is obviously a bit complicated (plus hard-coding the value isn't a great way to do this).
What you could use is some sort of service announcement - e.g. via mDNS. This works by having the server periodically announce "I'm a little server, short and stout (server of WhateverYourAppIsCalled on port 12345)" and your clients to listen for such requests, or even requesting them ("is there a server of WhateverYourAppIsCalled around here?"). See also this: http://en.wikipedia.org/wiki/Zero_configuration_networking#Service_discovery
(In a pinch, you could make the server broadcast its presence to the network and have the clients listen for such broadcasts, but then you're basically re-implementing mDNS)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With