Beispiel #1
0
 static public int constructor(IntPtr l)
 {
     try {
         int            argc = LuaDLL.lua_gettop(l);
         Hugula.Net.Msg o;
         if (argc == 1)
         {
             o = new Hugula.Net.Msg();
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 2)
         {
             System.Byte[] a1;
             checkArray(l, 2, out a1);
             o = new Hugula.Net.Msg(a1);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #2
0
 static public int get_Type(IntPtr l)
 {
     try {
         Hugula.Net.Msg self = (Hugula.Net.Msg)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.Type);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #3
0
 static public int ToCArray(IntPtr l)
 {
     try {
         Hugula.Net.Msg self = (Hugula.Net.Msg)checkSelf(l);
         var            ret  = self.ToCArray();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #4
0
 static public int WriteBoolean(IntPtr l)
 {
     try {
         Hugula.Net.Msg self = (Hugula.Net.Msg)checkSelf(l);
         System.Boolean a1;
         checkType(l, 2, out a1);
         self.WriteBoolean(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #5
0
 static public int set_Type(IntPtr l)
 {
     try {
         Hugula.Net.Msg self = (Hugula.Net.Msg)checkSelf(l);
         int            v;
         checkType(l, 2, out v);
         self.Type = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #6
0
 static public int ReadUTF(IntPtr l)
 {
     try {
         Hugula.Net.Msg self = (Hugula.Net.Msg)checkSelf(l);
         System.Int32   a1;
         checkType(l, 2, out a1);
         var ret = self.ReadUTF(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #7
0
 public void Send(Msg msg)
 {
     if (client != null && client.Connected)
         Send(msg.ToCArray());
     else
         sendQueue.Add(msg);
 }
Beispiel #8
0
        public void Receive()
        {
            ushort len = 0;
            byte[] buffer = null;
            ushort readLen = 0;
            while (client.Connected)
            {
                if (len == 0)
                {
                    byte[] header = new byte[2];
                    stream.Read(header, 0, 2);
                    Array.Reverse(header);
                    len = BitConverter.ToUInt16(header, 0);
                    buffer = new byte[len];
                    readLen = 0;
                    //if (len > client.ReceiveBufferSize)//������ȴ����˻�����
                    //{
                    //    buffer = new byte[len];
                    //}
                    //else
                    //{
                    //    buffer = null;
                    //}
                }

                if (len > 0 && readLen < len)
                {
                    int offset = readLen;//��ʼ��
                    int msgLen = client.Available;//�ɶ�����
                    int size = offset + msgLen;
                    if (size > len)//����ɶ����ȴ���len
                    {
                        msgLen = len - offset;
                    }

                    stream.Read(buffer, offset, msgLen);
                    readLen = Convert.ToUInt16(offset + msgLen);
                    if (readLen >= len)//��ȡ���
                    {
                        Msg msg = new Msg(buffer);
                        queue.Add(msg);
                        len = 0;
                    }
                }
                //if (len > 0 && buffer==null && len <= client.Available) //���û�з�ҳ
                //{
                //    byte[] message = new byte[len];
                //    stream.Read(message, 0, message.Length);
                //    Msg msg = new Msg(message);
                //    queue.Add(msg);
                //    len = 0;
                //}
                //else if (len > 0 && buffer != null)
                //{

                //}

                Thread.Sleep(16);
            }
        }