コード例 #1
0
 public void init(string host, int port, TcpDispatchCallback dispatcher, object msgPackAndSendFunc, object msgUnpackFunc)
 {
     mDispatcher             = dispatcher;
     this.msgPackAndSendFunc = msgPackAndSendFunc;
     this.msgUnpackFunc      = msgUnpackFunc;
     this.host = host;
     this.port = port;
 }
コード例 #2
0
 public Tcp(TcpDispatchCallback dispatcher)
 {
     mDispatcher = dispatcher;
 }
コード例 #3
0
 public Tcp(TcpDispatchCallback dispatcher, object msgPackAndSendFunc, object msgUnpackFunc)
 {
     mDispatcher             = dispatcher;
     this.msgPackAndSendFunc = msgPackAndSendFunc;
     this.msgUnpackFunc      = msgUnpackFunc;
 }
コード例 #4
0
 public void unpackMsg(USocket s, MemoryStream buffer, TcpDispatchCallback dispatcher)
 {
     try
     {
         bool isLoop = true;
         while (isLoop)
         {
             long totalLen = buffer.Position;
             if (totalLen > 2)
             {
                 buffer.SetLength(totalLen);
                 object o = null;
                 buffer.Position = 0;
                 if (msgUnpackFunc != null)
                 {
                     object[] objs = Utl.doCallback(msgUnpackFunc, s, buffer);
                     if (objs != null && objs.Length > 0)
                     {
                         o = objs[0];
                     }
                 }
                 else
                 {
                     o = defaultUnpackMsg(s, buffer);
                 }
                 if (o != null && dispatcher != null)
                 {
                     dispatcher(o, this);
                 }
                 long usedLen = buffer.Position;
                 if (usedLen > 0)
                 {
                     long leftLen = totalLen - usedLen;
                     if (leftLen > 0)
                     {
                         byte[] lessBuff = new byte[leftLen];
                         buffer.Read(lessBuff, 0, (int)leftLen);
                         buffer.Position = 0;
                         buffer.Write(lessBuff, 0, (int)leftLen);
                         buffer.SetLength((int)leftLen);
                     }
                     else
                     {
                         buffer.Position = 0;
                         buffer.SetLength(0);
                         isLoop = false;
                     }
                 }
                 else
                 {
                     buffer.Position = totalLen;
                     isLoop          = false;
                 }
             }
             else
             {
                 isLoop = false;
             }
         }
     } catch (System.Exception e) {
         Debug.LogError(e);
     }
 }