Reputation: 73
I am creating a service that will listen to a given port number until it receives a signal from an application running on a different machine. Both will have a default port number assigned, but I will need to include the ability to change the port number for conflict resolution.
My problem is how to do this within the service without a GUI, so I am assuming that I will create a simple config application that will update the port number that the service is listening on.
My question is, what is the best way to facilitate the communication between the application and the service? I have read a little on WCF. Is this where I need to focus more research?
Upvotes: 1
Views: 194
Reputation: 2073
In case you are using TCP socket to connect then you could do something like:
private TcpClient GetClient()
{
TcpClient client = null;
if (!string.IsNullOrEmpty(IpAddress)) // Get IpAddress from config
{
IPAddress ipAddress = null;
IPAddress.TryParse(IpAddress, out ipAddress);
if (ipAddress != null)
{
int intIpAddress = BitConverter.ToInt32(ipAddress.GetAddressBytes(), 0);
IPAddress clientBindingIp = new IPAddress(BitConverter.GetBytes(intIpAddress));
IPEndPoint endpoint = new IPEndPoint(clientBindingIp, 0); // Specify 0 for OS to automatically assign, or read from config here
client = new TcpClient(endpoint);
}
}
return client;
}
The thing is that if you dont specify a port number than while creating the socket the OS will assign a default available port number. Or you could read it from Config if you wish
Upvotes: 0
Reputation: 50
You can Use SignalR to communicate between your WPF and windows service.
Upvotes: 1