/
RemotingServer.cs
45 lines (35 loc) · 1.36 KB
/
RemotingServer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using MultiMiner.Utility.OS;
using System;
using System.Net;
using System.ServiceModel;
namespace MultiMiner.Remoting
{
public class RemotingServer
{
private bool serviceStarted = false;
private ServiceHost myServiceHost = null;
public void Startup()
{
//use Dns.GetHostName() instead of localhost for compatibility with Mono+Linux
//https://github.com/nwoolls/MultiMiner/issues/62
string hostname = Dns.GetHostName();
if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
//otherwise Windows -> OS X gets connection refused (though Linux -> OS X works)
hostname = "localhost";
Uri baseAddress = new Uri(String.Format("net.tcp://{0}:{1}/RemotingService", hostname, Config.RemotingPort));
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
myServiceHost = new ServiceHost(typeof(RemotingService), baseAddress);
myServiceHost.AddServiceEndpoint(typeof(IRemotingService), binding, baseAddress);
myServiceHost.Open();
serviceStarted = true;
}
public void Shutdown()
{
if (!serviceStarted)
return;
myServiceHost.Close();
myServiceHost = null;
serviceStarted = false;
}
}
}