/// <summary> /// 向远程发送一条消息 /// </summary> /// <param name="dat">数据</param> /// <param name="point">远程地址</param> /// <param name="tag">数据类型</param> /// <returns></returns> public bool Send(byte[] dat, IPEndPoint point, byte tag) { try { if (Packaging) { var buf = envelope.Pack(dat, tag); if (buf != null) { for (int i = 0; i < buf.Length; i++) { soc.SendTo(buf[i], point); } } } else { soc.SendTo(dat, point); } return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 向服务器发送消息 /// </summary> /// <param name="data"></param> public bool SendMessage(byte[] data, byte type) { if (client == null) { return(false); } try { if (Packaging) { var buf = envelope.Pack(data, type); if (buf != null) { for (int i = 0; i < buf.Length; i++) { client.Send(buf[i]); } } } else { client.Send(data); } } catch (Exception ex) { reConnect = true; return(false); } return(true); }
public int Send(byte[] data, byte type = EnvelopeType.Mate) { try { if (Link != null) { lock (Link) if (Link.Connected) { var ss = envelope.Pack(data, type); for (int i = 0; i < ss.Length; i++) { Link.Send(ss[i]); } return(1); } else { return(-1); } } } catch (Exception ex) { UnityEngine.Debug.Log(ex.StackTrace); return(-1); } return(0); }
/// <summary> /// 发送一条消息 /// </summary> /// <param name="data">数据</param> /// <param name="type">数据类型</param> /// <returns></returns> public int Send(byte[] data, byte type = 0) { try { if (Link != null) { lock (Link) if (Link.Connected) { var ss = envelope.Pack(data, type); for (int i = 0; i < ss.Length; i++) { Link.Send(ss[i]); } return(1); } else { return(-1); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.StackTrace); return(-1); } return(0); }