// Host the chat instance within this EXE console application. public static void Main(string[] args) { Console.WriteLine("Enter your nickname [default=DefaultName]: "); string member = Console.ReadLine(); Console.WriteLine("Enter the mesh password: "******"") { member = "DefaultName"; } // Construct InstanceContext to handle messages on callback interface. // An instance of ChatApp is created and passed to the InstanceContext. InstanceContext site = new InstanceContext(new ChatApp()); // Create the participant with the given endpoint configuration // Each participant opens a duplex channel to the mesh // participant is an instance of the chat application that has opened a channel to the mesh NetPeerTcpBinding binding = new NetPeerTcpBinding("SecureChatBinding"); ChannelFactory <IChatChannel> cf = new DuplexChannelFactory <IChatChannel>(site, "SecureChatEndpoint"); //for PeerAuthenticationMode.Password, you need to specify a password cf.Credentials.Peer.MeshPassword = password; IChatChannel participant = cf.CreateChannel(); // Retrieve the PeerNode associated with the participant and register for online/offline events // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes. IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>(); ostat.Online += new EventHandler(OnOnline); ostat.Offline += new EventHandler(OnOffline); // Print instructions to user Console.WriteLine("{0} is ready", member); Console.WriteLine("Type chat messages after going Online"); Console.WriteLine("Press q<ENTER> to terminate this instance."); // Announce self to other participants participant.Join(member); while (true) { string line = Console.ReadLine(); if (line == "q") { break; } participant.Chat(member, line); } // Leave the mesh and close the proxy participant.Leave(member); ((IChannel)participant).Close(); cf.Close(); }
// Host the chat instance within this EXE console application. public static void Main() { // Get the memberId from configuration string member = ConfigurationManager.AppSettings["member"]; string issuerName = ConfigurationManager.AppSettings["issuer"]; // Construct InstanceContext to handle messages on callback interface. // An instance of ChatApp is created and passed to the InstanceContext. InstanceContext site = new InstanceContext(new ChatApp()); // Create the participant with the given endpoint configuration // Each participant opens a duplex channel to the mesh // participant is an instance of the chat application that has opened a channel to the mesh DuplexChannelFactory <IChatChannel> cf = new DuplexChannelFactory <IChatChannel>(site, "ChatEndpoint"); X509Certificate2 issuer = GetCertificate(StoreName.TrustedPeople, StoreLocation.CurrentUser, "CN=" + issuerName, X509FindType.FindBySubjectDistinguishedName); cf.Credentials.Peer.Certificate = GetCertificate(StoreName.My, StoreLocation.CurrentUser, "CN=" + member, X509FindType.FindBySubjectDistinguishedName); cf.Credentials.Peer.PeerAuthentication.CertificateValidationMode = X509CertificateValidationMode.Custom; cf.Credentials.Peer.PeerAuthentication.CustomCertificateValidator = new IssuerBasedValidator(issuer); IChatChannel participant = cf.CreateChannel(); // Retrieve the PeerNode associated with the participant and register for online/offline events // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes. IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>(); ostat.Online += new EventHandler(OnOnline); ostat.Offline += new EventHandler(OnOffline); // Print instructions to user Console.WriteLine("{0} is ready", member); Console.WriteLine("Type chat messages after going Online"); Console.WriteLine("Press q<ENTER> to terminate the application."); // Announce self to other participants participant.Join(member); while (true) { string message = Console.ReadLine(); if (message == "q") { break; } participant.Chat(member, message); } // Leave the mesh and close the proxy participant.Leave(member); ((IChannel)participant).Close(); cf.Close(); }
// Host the chat instance within this EXE console application. public static void Main() { // Get the memberId from configuration. string member = ConfigurationManager.AppSettings["member"]; string issuerName = ConfigurationManager.AppSettings["issuer"]; // <Snippet1> // Construct InstanceContext to handle messages on the callback interface. // An instance of ChatApp is created and passed to the InstanceContext. InstanceContext site = new InstanceContext(new ChatApp()); // Create the participant with the given endpoint configuration. // Each participant opens a duplex channel to the mesh. // Participant is an instance of the chat application that has opened a channel to the mesh. using (DuplexChannelFactory <IChatChannel> cf = new DuplexChannelFactory <IChatChannel>(site, "ChatEndpoint")) { X509Certificate2 issuer = GetCertificate( StoreName.CertificateAuthority, StoreLocation.CurrentUser, "CN=" + issuerName, X509FindType.FindBySubjectDistinguishedName); cf.Credentials.Peer.Certificate = GetCertificate(StoreName.My, StoreLocation.CurrentUser, "CN=" + member, X509FindType.FindBySubjectDistinguishedName); cf.Credentials.Peer.PeerAuthentication.CertificateValidationMode = X509CertificateValidationMode.Custom; cf.Credentials.Peer.PeerAuthentication.CustomCertificateValidator = new IssuerBasedValidator(); using (IChatChannel participant = cf.CreateChannel()) { // Retrieve the PeerNode associated with the participant and register for online/offline events. // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes. IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>(); ostat.Online += new EventHandler(OnOnline); ostat.Offline += new EventHandler(OnOffline); Console.WriteLine("{0} is ready", member); Console.WriteLine("Press <ENTER> to send the chat message."); // Announce self to other participants. participant.Join(member); Console.ReadLine(); participant.Chat(member, "Hi there - I am chatting"); Console.WriteLine("Press <ENTER> to terminate this instance of chat."); Console.ReadLine(); // Leave the mesh and close the client. participant.Leave(member); } } // </Snippet1> }
public bool SendMessage(string message) { try { //MessageBox.Show("Send: " + message); participant.Chat(member, message); return(true); } catch { return(false); } }
// Host the chat instance within this EXE console application. public static void Main() { Console.WriteLine("Enter your nickname [default=DefaultName]: "); string member = Console.ReadLine(); if (member == "") { member = "DefaultName"; } // Construct InstanceContext to handle messages on callback interface. // An instance of ChatApp is created and passed to the InstanceContext. InstanceContext instanceContext = new InstanceContext(new ChatApp(member)); // Create the participant with the given endpoint configuration // Each participant opens a duplex channel to the mesh // participant is an instance of the chat application that has opened a channel to the mesh DuplexChannelFactory <IChatChannel> factory = new DuplexChannelFactory <IChatChannel>(instanceContext, "ChatEndpoint"); IChatChannel participant = factory.CreateChannel(); // Retrieve the PeerNode associated with the participant and register for online/offline events // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes. IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>(); ostat.Online += new EventHandler(OnOnline); ostat.Offline += new EventHandler(OnOffline); try { participant.Open(); } catch (CommunicationException) { Console.WriteLine("Could not find resolver. If you are using a custom resolver, please ensure"); Console.WriteLine("that the service is running before executing this sample. Refer to the readme"); Console.WriteLine("for more details."); return; } Console.WriteLine("{0} is ready", member); Console.WriteLine("Type chat messages after going Online"); Console.WriteLine("Press q<ENTER> to terminate this instance."); // Announce self to other participants participant.Join(member); // loop until the user quits while (true) { string line = Console.ReadLine(); if (line == "q") { break; } participant.Chat(member, line); } // Leave the mesh participant.Leave(member); participant.Close(); factory.Close(); }