Created
March 5, 2015 23:02
-
-
Save yallie/800cbd737cc74375a3dc to your computer and use it in GitHub Desktop.
TcpEx bug #2414: disposing the host doesn't release the tcp port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tcp version works properly | |
// TcpEx version (commented lines) crashes | |
using System; | |
using System.Linq; | |
using Zyan.Communication; | |
using Zyan.Communication.Protocols.Tcp; | |
using Zyan.Communication.Security; | |
using Zyan.Communication.SessionMgmt; | |
class Program | |
{ | |
static void Main() | |
{ | |
try | |
{ | |
RunServer(); | |
} | |
catch | |
{ | |
RunClient(); | |
} | |
} | |
static void RunServer() | |
{ | |
RunAndStopServer(); | |
RunAndStopServer(); | |
} | |
static void RunAndStopServer() | |
{ | |
//var protocol = new TcpDuplexServerProtocolSetup(9042, new NullAuthenticationProvider(), true); | |
var protocol = new TcpCustomServerProtocolSetup(9042, new NullAuthenticationProvider()); | |
var host = new ZyanComponentHost("MyService", protocol); | |
host.PollingEventTracingEnabled = true; | |
host.RegisterComponent<IMyService, MyService>(ActivationType.Singleton); | |
host.EnableDiscovery(); | |
Console.WriteLine("Server started, press ENTER to stop."); | |
Console.ReadLine(); | |
host.UnregisterComponent<IMyService>(); | |
host.PollingEventTracingEnabled = false; | |
host.DisableDiscovery(); | |
host.Dispose(); | |
} | |
public interface IMyService { string Version { get; } } | |
public class MyService : IMyService { public string Version { get { return "None"; } } } | |
static void RunClient() | |
{ | |
// client side | |
//var protocol = new TcpDuplexClientProtocolSetup(true); | |
//var connection = new ZyanConnection("tcpex://localhost:9042/MyService", protocol); | |
var protocol = new TcpCustomClientProtocolSetup(true); | |
var connection = new ZyanConnection("tcp://localhost:9042/MyService", protocol); | |
var myServerProxy = connection.CreateProxy<IMyService>(); | |
System.Console.WriteLine(myServerProxy.Version); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment