Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Peer to peer chat
    primarykey
    data
    text
    <p>I wrote some code for a WCF P2P chat program.</p> <pre><code>&lt;services&gt; &lt;service name="PeerChat.Form1"&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="net.p2p://PeerChat/" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;endpoint name="PeerChatEndPoint" address="" binding="netPeerTcpBinding" bindingConfiguration="BindingUnsecure" contract="PeerChat.IChatService" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;bindings&gt; &lt;netPeerTcpBinding&gt; &lt;binding name="BindingUnsecure"&gt; &lt;resolver mode="Pnrp" /&gt; &lt;security mode="None" /&gt; &lt;/binding&gt; &lt;/netPeerTcpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint name="PeerChatClientEndPoint" address="net.p2p://PeerChat/" binding="netPeerTcpBinding" bindingConfiguration="BindingUnsecure" contract="PeerChat.IChatService" /&gt; &lt;/client&gt; </code></pre> <p>I then host the service as follows:</p> <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] public partial class Form1 : Form, IChatService { IChatService channel; ServiceHost host = null; ChannelFactory&lt;IChatService&gt; channelFactory = null; private void StartService() { //Instantiate new ServiceHost host = new ServiceHost(this); //Open ServiceHost host.Open(); //Create a ChannelFactory and load the configuration setting channelFactory = new ChannelFactory&lt;IChatService&gt;("PeerChatClientEndPoint"); channel = channelFactory.CreateChannel(); //Lets others know that someone new has joined channel.SendMessage("Hello."+ Environment.NewLine); foreach (var cloud in Cloud.GetAvailableClouds()) { textBox2.Text += cloud.Name + Environment.NewLine; } } private void StopService() { if (host != null) { channel.SendMessage("Bye." + Environment.NewLine); if (host.State != CommunicationState.Closed) { channelFactory.Close(); host.Close(); } } } </code></pre> <p>The problem is I can send a message to the same instance of the program but not to another instance. Ie an instance only receives its own messages not messages from other instances. Not sure if it is a matter of configuring PNRP correctly? I tested on Windows 7. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload