private void P2p_receiveServerEventbit(byte command, byte[] data) { try { if (data.Length < 6) { return; } byte[] b = new byte[6]; data.CopyTo(b, data.Length - b.Length); ConnObj cobj = GateHelper.GetConnItemlistByindex(ConnItemlist, b, Pipeline); if (cobj != null) { int error = 0; lb1122: if (!p2psev.Send(cobj.Soc, command, data)) { error += 1; EventMylog("转发" + error, "ConnObjlist:发送失败:byte"); if (error < 3) { goto lb1122; } } } else { EventMylog("转发", "ConnObjlist:byte是空的"); } return; } catch { } }
/// <summary> /// 这里写接收到服务器发送的消息转发给客户端 /// </summary> /// <param name="command"></param> /// <param name="text"></param> protected void V_receiveServerEvent(byte command, string text) { try { if (text == "") { return; } WeaveSession _0x01 = null; try { _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(text); } catch { return; } int temp = 0; String ip = ""; int port = 0; try { ip = _0x01.Token.Split(':')[0]; port = Convert.ToInt32(_0x01.Token.Split(':')[1]); _0x01.Querycount = temp; } catch { EventMylog("转发", "获取编号失败。" + _0x01.Token); return; } ConnObj cobj = GateHelper.GetConnItemlist(ConnItemlist, ip, port, Pipeline); if (cobj != null) { int error = 0; lb1122: if (!p2psev.Send(cobj.Soc, command, text)) { error += 1; EventMylog("转发" + error, "ConnObjlist:发送失败:" + text); if (error < 3) { goto lb1122; } } } else { EventMylog("转发", "ConnObjlist:" + temp + "是空的"); } return; } catch (Exception ex) { EventMylog("转发", ex.Message + "112223333333333356464122313" + text + "000000"); } }
protected void p2psev_EventDeleteConnSoc(System.Net.Sockets.Socket soc) { try { counttemp--; IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint; List <String> listsercer = new List <string>(); bool tempb = true; foreach (CommandItem ci in CommandItemS) { tempb = true; foreach (string ser in listsercer) { if (ser == (ci.Ip + ci.Port)) { tempb = false; goto lab882; } } lab882: if (tempb) { if (ci.Client4_10[0, 0, 0, 0] != null) { listsercer.Add(ci.Ip + ci.Port); String tempip = ci.Ip + ":" + ci.Port; ci.Client4_10[0, 0, 0, Convert.ToInt32(clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 1, 1))].send(0xff, "out|" + tempip); } } } GateHelper.removeConnItemlist(ConnItemlist, soc, Pipeline); } catch (Exception ex) { if (EventMylog != null) { EventMylog("移除用户", ex.Message); } } }
/// <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); } } }
/// <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); } } }
protected void p2psev_EventUpdataConnSoc(System.Net.Sockets.Socket soc) { ConnObj cobj = new ConnObj(); try { cobj.Soc = soc; IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint; counttemp++; //这里通过IP和PORT获取对象 cobj.Token = clientipe.Address.ToString() + ":" + clientipe.Port;// EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc"); cobj.Soc = soc; if (counttemp > max) { int mincount = int.MaxValue; string tempip = ""; foreach (WayItem ci in WayItemS) { if (ci.Num < mincount) { mincount = ci.Num; tempip = ci.Ip + ":" + ci.Port; } } if (Wptype == WeavePortTypeEnum.Bytes) { p2psev.Send(soc, 0xff, UTF8Encoding.UTF8.GetBytes("jump|" + tempip + "")); } else { p2psev.Send(soc, 0xff, "jump|" + tempip + ""); } soc.Close(); return; } //IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint; if (Wptype != WeavePortTypeEnum.Bytes) { p2psev.Send(soc, 0xff, "token|" + cobj.Token + ""); } GateHelper.SetConnItemlist(ConnItemlist, cobj, Pipeline); List <String> listsercer = new List <string>(); bool tempb = true; foreach (CommandItem ci in CommandItemS) { tempb = true; foreach (string ser in listsercer) { if (ser == (ci.Ip + ci.Port)) { tempb = false; goto lab882; } } lab882: if (tempb) { if (ci.Client4_10[0, 0, 0, 0] != null) { listsercer.Add(ci.Ip + ci.Port); ci.Client4_10[0, 0, 0, Convert.ToInt32(clientipe.Port.ToString().Substring(clientipe.Port.ToString().Length - 1, 1))].send(0xff, "in|" + cobj.Token); } } } } catch (Exception ex) { if (EventMylog != null) { EventMylog("EventUpdataConnSoc", ex.Message); } } }