示例#1
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     try
     {
         cprs = new CustomPeerResolverService();
         cprs.RefreshInterval = TimeSpan.FromSeconds(5);
         host = new ServiceHost(cprs);
         host.BaseAddresses[0].AbsoluteUri.Replace(host.BaseAddresses[0].AbsoluteUri.ToString(), string.Format("net.tcp://{0}/ChatServer", IPAddress));
         host.Description.Endpoints[0].Address   = new EndpointAddress(new Uri(string.Format("net.tcp://{0}/ChatServer", IPAddress)));
         host.Description.Endpoints[0].ListenUri = new Uri(string.Format("net.tcp://{0}/ChatServer", IPAddress));
         cprs.ControlShape = true;
         cprs.Open();
         host.Open(TimeSpan.FromDays(1000000));
         lblMessage.Text = "Server started successfully.";
         ChatClient.ChatClient frm = new ChatClient.ChatClient();
         frm.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         btnStart.Enabled = false;
         btnStop.Enabled  = true;
     }
 }
示例#2
0
        private void gvCalendar_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string Address = string.Format(CultureInfo.InvariantCulture, "net.tcp://{0}/ChatServer", IPAddress);

                /*
                 * NetTcpBinding binding = new NetTcpBinding();
                 * binding.Security.Mode = SecurityMode.None;
                 * binding.MaxReceivedMessageSize = 1000000;
                 * binding.OpenTimeout = TimeSpan.FromMinutes(10);
                 * binding.SendTimeout = TimeSpan.FromMinutes(5);
                 * binding.ReceiveTimeout = TimeSpan.FromMinutes(5);
                 * binding.MaxBufferPoolSize = 1000000;
                 * binding.MaxConnections = 6;
                 * binding.MaxBufferSize = 1000000;
                 * binding.ReliableSession.Ordered = false;
                 * binding.ReliableSession.Enabled = false;
                 * binding.TransferMode = TransferMode.Streamed;
                 *
                 * System.ServiceModel.PeerResolvers.CustomPeerResolverService crs = new System.ServiceModel.PeerResolvers.CustomPeerResolverService();
                 * crs.RefreshInterval = TimeSpan.FromSeconds(5);
                 * crs.ControlShape = true;
                 * ServiceHost Resolver = new ServiceHost(crs, URiAddress);
                 * Resolver.AddServiceEndpoint(typeof(System.ServiceModel.PeerResolvers.IPeerResolverContract), new NetTcpBinding(),Address, URiAddress);
                 * Resolver.OpenTimeout = TimeSpan.FromMinutes(5);
                 * crs.Open();
                 * Resolver.Open(TimeSpan.FromDays(100000));
                 */

                cprs = new CustomPeerResolverService();
                cprs.RefreshInterval = TimeSpan.FromSeconds(5);
                host = new ServiceHost(cprs);
                //ServiceDiscoveryBehavior discoveryBehavior = new ServiceDiscoveryBehavior();
                //host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                //discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
                host.BaseAddresses[0].AbsoluteUri.Replace(host.BaseAddresses[0].AbsoluteUri.ToString(), string.Format("net.tcp://{0}/ChatServer", IPAddress));
                host.Description.Endpoints[0].Address   = new EndpointAddress(new Uri(string.Format("net.tcp://{0}/ChatServer", IPAddress)));
                host.Description.Endpoints[0].ListenUri = new Uri(string.Format("net.tcp://{0}/ChatServer", IPAddress));
                //host.Description.Endpoints.Add(new UdpDiscoveryEndpoint());
                cprs.ControlShape = true;
                cprs.Open();
                host.Open(TimeSpan.FromDays(1000000));

                btnStart.Enabled = false;
                btnStop.Enabled  = true;
                string Message = "Server started successfully.";
                string date    = "";
                date = Convert.ToString(gvCalendar.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) + "-" + cmbMonth.SelectedValue + "-" + cmbYear.SelectedValue;

                ChatClient.ChatClient frm = new ChatClient.ChatClient(MachineUserName, date);
                frm.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }