public AutoconClient(string name, string ipaddr, int port)
        {
            this.name      = name;
            this.ipaddr    = ipaddr;
            this.port      = port;
            this.connected = false;

            var uri     = new Uri(string.Format("net.tcp://{0}:{1}", ipaddr, port));
            var binding = new NetTcpBinding();

            binding.Name        = "MasterConnBinding";
            binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 500);            // shorten the timeout when accessing the service
            //binding.ReceiveTimeout = new TimeSpan(0,0,0,10,0); //  interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.
            binding.MaxReceivedMessageSize = Int32.MaxValue;                // default 65535 is not enough for long plans
            binding.CloseTimeout           = new TimeSpan(0, 0, 0, 0, 500); // shorten the timeout when closing the channel
            binding.Security.Mode          = SecurityMode.None;
            callback = new MasterServiceCallback();
            client   = new MasterServiceClient(callback, binding, new EndpointAddress(uri));

            terminate        = false;
            connectionThread = new Thread(connectionThreadLoop);
            connectionThread.Start();
        }
示例#2
0
        public void Connect()
        {
            var uri     = new Uri(string.Format("net.tcp://{0}:{1}", ipaddr, port));
            var binding = new NetTcpBinding();

            binding.Name = "MasterConnBinding";
            //binding.SendTimeout = new TimeSpan(0,0,0,0,500); // shorten the timeout when accessing the service
            binding.CloseTimeout           = new TimeSpan(0, 0, 0, 0, 500); // shorten the timeout when closing the channel and there is an error
            binding.MaxReceivedMessageSize = Int32.MaxValue;                // default 65535 is not enough for long plans
            binding.Security.Mode          = SecurityMode.None;
            callback = new MasterServiceCallback();
            client   = new MasterServiceClient(callback, binding, new EndpointAddress(uri));
            server   = client.ChannelFactory.CreateChannel();

            try
            {
                server.AddClient(name);
            }
            catch
            {
                CloseChannel();
                throw new MasterConnectionTimeoutException(ipaddr, port);
            }
        }