Author: marcosc
Date: 2007-07-19 07:37:17 -0400 (Thu, 19 Jul 2007)
New Revision: 82279

Added:
   trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatClient.cs
Modified:
   trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatServer.cs
   trunk/olive/samples/services/net-peer-tcp-binding-chat/Makefile
Log:
ChatClient.cs, ChatServer.cs: Working sample under .NET, used for Mono hacking.
Makefile: Updated.

Added: trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatClient.cs
===================================================================
--- trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatClient.cs        
2007-07-19 11:33:54 UTC (rev 82278)
+++ trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatClient.cs        
2007-07-19 11:37:17 UTC (rev 82279)
@@ -0,0 +1,84 @@
+// 
+// ChatClient.cs
+// 
+// Author: 
+//     Marcos Cobena ([EMAIL PROTECTED])
+// 
+// Copyright 2007 Marcos Cobena (http://www.youcannoteatbits.org/)
+// 
+
+using System;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.PeerResolvers;
+
+namespace ChatClient
+{
+       public class ChatClient : IChatService
+       {
+               string username;
+               
+               public ChatClient (string username)
+               {
+                       this.username = username;
+               }
+               
+               public static void Main ()
+               {
+                       InstanceContext ic = new InstanceContext (new 
ChatClient ("Marcos"));
+                       NetPeerTcpBinding nptb = new NetPeerTcpBinding ();
+                       NetTcpBinding ntb = new NetTcpBinding ();
+                       ntb.Security.Mode = SecurityMode.None;
+                       nptb.Resolver.Custom.Address = new EndpointAddress 
("net.tcp://localhost/ChatServer");
+                       nptb.Resolver.Custom.Binding = ntb;
+                       nptb.Resolver.Mode = PeerResolverMode.Auto;
+//                     nptb.Resolver.ReferralPolicy = 
PeerReferralPolicy.Service;
+                       nptb.Security.Mode = SecurityMode.None;
+                       DuplexChannelFactory<IChatChannel> factory = 
+                               new DuplexChannelFactory<IChatChannel> (ic, 
+                                                                       nptb, 
+                                                                       new 
EndpointAddress ("net.p2p://chatMesh/ChatServer"));
+                       Console.WriteLine ("Here!");
+                       IChatChannel channel = factory.CreateChannel ();
+                       channel.Open ();
+                       channel.Join ("Marcos");
+                       // Right here, run the same process separately.
+                       Console.ReadLine ();
+                       channel.Leave ("Marcos");
+                       channel.Close ();
+                       factory.Close ();
+               }
+               
+               public void Join (string username)
+               {
+                       Console.WriteLine ("\"{0}\" joined the conversation.", 
username);
+               }
+               
+               public void Leave (string username)
+               {
+                       Console.WriteLine ("\"{0}\" left the conversation.", 
username);
+               }
+               
+               public void SendMessage (string username, string message)
+               {
+                       throw new NotImplementedException ();
+               }
+       }
+       
+       [ServiceContract (CallbackContract = typeof (IChatService))]
+       public interface IChatService
+       {
+               [OperationContract (IsOneWay = true)]
+               void Join (string username);
+               
+               [OperationContract (IsOneWay = true)]
+               void Leave (string username);
+               
+               [OperationContract (IsOneWay = true)]
+               void SendMessage (string username, string message);
+       }
+       
+       public interface IChatChannel : IChatService, IClientChannel
+       {
+       }
+}

Modified: trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatServer.cs
===================================================================
--- trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatServer.cs        
2007-07-19 11:33:54 UTC (rev 82278)
+++ trunk/olive/samples/services/net-peer-tcp-binding-chat/ChatServer.cs        
2007-07-19 11:37:17 UTC (rev 82279)
@@ -15,6 +15,7 @@
 
 namespace ChatServer
 {
+       // It works as .NET service, don' touch.
        public class ChatServer
        {
                public static void Main ()
@@ -26,21 +27,15 @@
 
                        try {
                                cprs = new CustomPeerResolverService ();
-
-                               cprs.RefreshInterval = TimeSpan.FromSeconds (5);
-
                                sh = new ServiceHost (cprs);
-                               
                                binding = new NetTcpBinding ();
                                binding.Security.Mode = SecurityMode.None;
-                               
                                se = sh.AddServiceEndpoint (typeof 
(IPeerResolverContract), 
                                                               binding, 
                                                               new Uri 
("net.tcp://localhost/ChatServer"));
-                               
-                               cprs.ControlShape = true;
+                               cprs.ControlShape = false;
                                cprs.Open ();
-                               sh.Open (TimeSpan.FromDays (1000000));
+                               sh.Open ();
                                
                                Console.WriteLine ("Server started 
successfully.");
                                Console.ReadLine ();

Modified: trunk/olive/samples/services/net-peer-tcp-binding-chat/Makefile
===================================================================
--- trunk/olive/samples/services/net-peer-tcp-binding-chat/Makefile     
2007-07-19 11:33:54 UTC (rev 82278)
+++ trunk/olive/samples/services/net-peer-tcp-binding-chat/Makefile     
2007-07-19 11:37:17 UTC (rev 82279)
@@ -1,7 +1,10 @@
-all: ChatServer.exe
-
-ChatServer.exe : ChatServer.cs
-       gmcs -debug -pkg:olive ChatServer.cs
-
-clean:
-       rm ChatServer.exe ChatServer.exe.mdb
\ No newline at end of file
+all: ChatClient.exe ChatServer.exe
+
+ChatClient.exe : ChatClient.cs
+       gmcs -debug -pkg:olive ChatClient.cs
+
+ChatServer.exe : ChatServer.cs
+       gmcs -debug -pkg:olive ChatServer.cs
+
+clean:
+       rm *.exe *.exe.mdb

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to