コード例 #1
0
        public override bool getdata(HttpProcessor p, byte command, string data)
        {
            string returnstr = "";

            foreach (CommandItem ci in CommandItems)
            {
                if (ci.CommName == command)
                {
                    P2Pclient p2p = new P2Pclient(false);
                    p2p.ReceiveServerEvent += new P2Pclient.receive((c, text) => {
                        returnstr = text;
                    });
                    //p2p.timeoutevent += (V_timeoutevent);
                    p2p.ErrorMge += (V_ErrorMge);
                    if (p2p.Start(ci.Ip, ci.Port, false))
                    {
                        System.Threading.Thread.Sleep(200);
                        p2p.Send(command, data);
                        int count = 0;
                        while (returnstr == "")
                        {
                            System.Threading.Thread.Sleep(200);
                            if (count > 450)
                            {
                                p.outputStream.WriteLine("响应超时");
                                return(false);
                            }
                            count++;
                        }
                        p.outputStream.WriteLine(returnstr);
                        return(true);
                    }
                    else
                    {
                        p.outputStream.WriteLine("不能连接指定的服务");
                        return(false);
                    }
                }
                // _0x01.
            }
            p.outputStream.WriteLine("不能找到指定的服务");
            int i = httpProcessorList.Count;

            HttpProcessor[] hps = new HttpProcessor[i];
            httpProcessorList.CopyTo(hps);
            foreach (HttpProcessor hp in hps)
            {
                if (hp == p)
                {
                    httpProcessorList.Remove(p);
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: dreamsfly900/weaving-socket
        //int i = 0;
        void tt()
        {
            // timer1.Start();
            for (int i = 0; i < 300; i++)
            {
                P2Pclient p2pc = new P2Pclient(DataType.custom);
                p2pc.ReceiveServerEvent    += P2pc_receiveServerEvent; //接收数据事件
                p2pc.ReceiveServerEventbit += P2pc_receiveServerEventbit;
                p2pc.Timeoutevent          += P2pc_timeoutevent;       //超时(掉线)事件
                p2pc.Start("127.0.0.1", 8989, false);                  //11002 是网关的端口号,刚才WEB网关占用了11001,我改成11002了

                p2pc.Send(new byte[1000]);
                //p2pc.SendRoot<int>(0x01, "login", 99987, 0);
                System.Threading.Thread.Sleep(5);
            }
        }
コード例 #3
0
        /// <summary>
        /// 收到客户端发来的消息,并转发到服务端中心
        /// </summary>
        /// <param name="command"></param>
        /// <param name="data"></param>
        /// <param name="soc"></param>
        protected void p2psev_receiveevent(byte command, string data, System.Net.Sockets.Socket soc)
        {
            try
            {
                // JSON.parse<_baseModel>(data);//
                WeaveSession _0x01;
                try
                {
                    _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(data);
                }
                catch
                {
                    EventMylog("JSON解析错误:", "" + data);
                    return;
                }
                if (_0x01.Token == null)
                {
                    EventMylog("Token是NULL:", "" + data);
                    return;
                }

                IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;

                int count = CommandItemS.Count;

                try
                {
                    // temp = _0x01.Token.Split(':');
                    //if (temp.Length < 2)
                    //    return;
                    _0x01.Token = clientipe.Address.ToString() + ":" + clientipe.Port;
                }
                catch (Exception e)
                {
                    if (EventMylog != null)
                    {
                        EventMylog("p2psev_receiveevent", e.Message);
                    }
                    return;
                }

                foreach (CommandItem ci in CommandItemS)
                {
                    if (ci != null)
                    {
                        if (ci.CommName == command)
                        {
                            P2Pclient[,,,] client4_10temp = ci.Client4_10;
                            P2Pclient p2ptemp = GateHelper.GetP2Pclient(client4_10temp, soc, Pipeline);
                            if (p2ptemp != null)
                            {
                                if (!p2ptemp.Isline)
                                {
                                    p2psev.Send(soc, 0xff, "你所请求的服务暂不能使用,已断开连接!"); return;
                                }
                                if (!p2ptemp.Send(command, _0x01.Getjson()))
                                {
                                    p2psev.Send(soc, 0xff, "你所请求的服务暂不能使用,发送错误。");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("p2psev_receiveevent----", ex.Message);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 收到客户端发来的Byte消息,并转发到服务端中心
        /// </summary>
        /// <param name="command"></param>
        /// <param name="data"></param>
        /// <param name="soc"></param>
        private void P2psev_weaveReceiveBitEvent(byte command, byte[] data, Socket soc)
        {
            try
            {
                // JSON.parse<_baseModel>(data);//


                IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;

                int count = CommandItemS.Count;

                try
                {
                    // temp = _0x01.Token.Split(':');
                    //if (temp.Length < 2)
                    //    return;
                    //_0x01.Token = clientipe.Address.ToString() + ":" + clientipe.Port;
                }
                catch (Exception e)
                {
                    if (EventMylog != null)
                    {
                        EventMylog("p2psev_receiveevent", e.Message);
                    }
                    return;
                }

                foreach (CommandItem ci in CommandItemS)
                {
                    if (ci != null)
                    {
                        if (ci.CommName == command)
                        {
                            P2Pclient[,,,] client4_10temp = ci.Client4_10;
                            P2Pclient p2ptemp = GateHelper.GetP2Pclient(client4_10temp, soc, Pipeline);
                            byte[]    b       = GateHelper.GetP2PclientIndex(client4_10temp, soc, Pipeline);
                            if (p2ptemp != null)
                            {
                                if (!p2ptemp.Isline)
                                {
                                    p2psev.Send(soc, 0xff, "你所请求的服务暂不能使用,已断开连接!"); return;
                                }
                                byte[] tempdata = new byte[data.Length + b.Length];
                                Array.Copy(data, 0, tempdata, 0, data.Length);
                                Array.Copy(b, 0, tempdata, data.Length - 1, b.Length);
                                if (!p2ptemp.Send(command, tempdata))
                                {
                                    p2psev.Send(soc, 0xff, "你所请求的服务暂不能使用,发送错误。");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("p2psev_receiveevent----", ex.Message);
                }
            }
        }