示例#1
0
 public NetworkEventArgs(RemoteInformation ri, NetworkContent content)
     : base()
 {
     this.RemoteInformation = ri;
     this.Content = content;
     this.Cancelled = false;
 }
示例#2
0
        void Server_DoWork(object sender, DoWorkEventArgs e)
        {
            IPEndPoint endpoint = e.Argument as IPEndPoint;
            BackgroundWorker worker = sender as BackgroundWorker;
            if (null == endpoint || null == worker) {
                e.Cancel = true;
                return;
            }

            endpoint.Address = IPAddress.Any;
            TcpListener lisenter = new TcpListener(endpoint);
            try {
                byte[] buf = new byte[256];

                lisenter.Start();
                worker.ReportProgress(0, null);

                while (true) {
                    if (worker.CancellationPending)
                        break;

                    if (lisenter.Pending()) {

                        TcpClient client = lisenter.AcceptTcpClient();
                        client.SendTimeout = client.ReceiveTimeout = this.Timeout;

                        if (null != client && client.Connected) {

                            RemoteInformation ri = new RemoteInformation();
                            ri.Connection = client;
                            ri.EndPoint = client.Client.RemoteEndPoint as IPEndPoint; //TODO: Need to verify - EndPoint as IPEndPoint
                            ri.Name = ri.EndPoint.ToString();
                            ri.Content = null;

                            worker.ReportProgress(1, ri); // progress == 1 means client connected.

                            // Do not dispose ri here.
                        }
                    }

                    Thread.Sleep(0);
                }

            } catch (SocketException err) {
            #if DEBUG
                throw err;
            #endif
                Trace.TraceError("Host socket error. \n{0}\n{1}", err.Message, err.StackTrace);
            } finally {
                lisenter.Stop();
            }

            e.Result = null;
        }
示例#3
0
        /// <summary>
        /// Call client without waiting for return
        /// </summary>
        /// <param name="ri">client information</param>
        /// <param name="content">data to send</param>
        /// <returns></returns>
        public bool CallClient(RemoteInformation ri, NetworkContent content)
        {
            if (null == ri || null == content)
                return false;

            return Host.SendData(ri.Connection, content.GetBinary());
        }