Exemplo n.º 1
0
 public NetworkEventArgs(RemoteInformation ri, NetworkContent content)
     : base()
 {
     this.RemoteInformation = ri;
     this.Content = content;
     this.Cancelled = false;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Send data to server without waiting return
        /// </summary>
        /// <param name="content">the data to send</param>
        /// <returns></returns>
        public bool CallServer(NetworkContent content)
        {
            if (null == m_client || null == content)
                return false;

            this.ErrorMessage = null;

            return Host.SendData(m_client, content.GetBinary());
        }
Exemplo n.º 3
0
        void Client_DoWork(object sender, DoWorkEventArgs e)
        {
            IPEndPoint hostEndPoint = e.Argument as IPEndPoint;
            BackgroundWorker worker = sender as BackgroundWorker;
            if (null == hostEndPoint || worker == null) {
                e.Cancel = true;
                return;
            }

            TcpClient client = new TcpClient();
            client.SendTimeout = client.ReceiveTimeout = this.Timeout;
            try {

                client.Connect(hostEndPoint);

                if (client.Connected) {

                    //trigger event Connected.
                    worker.ReportProgress(0, client);

                    while (true) {

                        if (worker.CancellationPending || !client.Connected)
                            break;

                        byte[] data = Host.RecevieData(client);
                        if (null != data) {
                            NetworkContent content = new NetworkContent(
                                EnumNetworkContentType.Bianary, data, this.Encoding);

                            // trigger DataValidating and HostCalled.
                            worker.ReportProgress(1, content);
                        }

                        System.Threading.Thread.Sleep(0);
                    }

                }
            } catch (SocketException err) {
            #if DEBUG
                throw err;
            #endif
                Trace.TraceError("Client socket error \n{0}\n{1}", err.ErrorCode, err);
            } finally {
                client.Close();
            }
        }
Exemplo n.º 4
0
        public void Boardcast(NetworkContent content)
        {
            if (null == m_worker || null == content || m_clients.Count == 0)
                return;

            foreach (string name in m_clients.Keys) {
                if (!this.CallClient(name, content))
                    m_clients[name].Worker.CancelAsync();
            }
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Call client without waiting for return
        /// </summary>
        /// <param name="name">client name</param>
        /// <param name="content">data to send</param>
        /// <returns></returns>
        public bool CallClient(string name, NetworkContent content)
        {
            if (string.IsNullOrEmpty(name) || null == content)
                return false;

            RemoteInformation ri = null;
            if (!m_clients.TryGetValue(name, out ri))
                return false;

            return this.CallClient(ri, content);
        }
Exemplo n.º 7
0
 public void CallClient(string clientName, string hostName, string command)
 {
     NetworkContent content = new NetworkContent(EnumNetworkContentType.String,
         string.Format("({0}#{1})", hostName, command));
     m_server.CallClient(clientName, content);
 }
Exemplo n.º 8
0
 bool OnClientDataValidating(NetworkContent data)
 {
     //throw new NotImplementedException();
     return true;
 }
Exemplo n.º 9
0
 public void DispatchCommand(NetworkContent content)
 {
     m_server.Boardcast(content);
 }
Exemplo n.º 10
0
        public void CallServer(string data)
        {
            Debug.Assert(!string.IsNullOrEmpty(data));

            if (m_client == null || string.IsNullOrEmpty(data))
                return;

            string command = string.Format("({0}#{1})", m_client.Name, data);
            NetworkContent content = new NetworkContent(EnumNetworkContentType.String, command);
            m_client.CallServer(content);
        }
Exemplo n.º 11
0
 bool OnServerDataValidating(NetworkContent data)
 {
     string s = data.GetString();
     if (s.StartsWith("(") && s.EndsWith(")"))
         return true;
     return false;
 }