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.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 callback = new MasterServiceCallback(); client = new MasterServiceClient(callback, binding, new EndpointAddress(uri)); terminate = false; connectionThread = new Thread(connectionThreadLoop); connectionThread.Start(); }
public async Task GetFileList() { var masterServiceClient = new MasterServiceClient(new MasterServiceClientSettings() { MasterServerIP = this.masterServerIP, MasterServerPort = this.masterServerPort }); masterServiceClient.Start(); // Always set callback at first. masterServiceClient.FileListReceived += (sender, args) => { this.fileList.Clear(); this.fileList.AddRange(args.FileList); Console.Beep(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Thông báo: Đã nhận được danh sách tập tin."); Console.ResetColor(); masterServiceClient.Stop(); }; await masterServiceClient.MasterServer.RequestFileList(); }