Exemplo n.º 1
0
        public bool Run()
        {
            // packet keys
            PacketKey   k   = new PacketKey();
            JSONBuilder kjb = new JSONBuilder();

            kjb.closeMe();
            k.addToJSON(kjb);

            Console.WriteLine(kjb.ToString());
            Console.WriteLine("====");

            // packets
            Packet p  = new Packet(new ComData("test"));
            string sp = p.Pack();

            Console.WriteLine(sp);

            Packet p2;

            Packet.Unpack(sp, out p2);

            Console.WriteLine(p2);

            return(true);
        }
Exemplo n.º 2
0
        protected void incommingRead(string msg)
        {
            Packet p;

            if (Packet.Unpack(msg, out p) && p.Key > lastPacketKey)
            {
                lastPacketKey = p.Key;
                if (VERBOSE)
                {
                    Console.WriteLine("Read <" + p.Key.getValue() + ">: " + p.Data.getDataType());
                }

                //request?
                string dt = p.Data.getDataType();
                if (dt.Equals(ComData.REQUEST))
                {
                    switch (p.Data.GetRequest())
                    {
                    case ComData.Request.RESET:     // todo - fix this
                        reset();
                        break;

                    case ComData.Request.CLOSE:
                        Close();
                        break;
                    }
                    return;
                }

                onReadData(p.Data);
            }

            beginRead(incommingRead);
        }
Exemplo n.º 3
0
        private Packet(string json)
        {
            JSONDecoder jd = new JSONDecoder(json);

            Key = new PacketKey();
            Key.fillFromJSON(jd);

            Data = new ComData("");
            jd.SkipLine();
            Data.fillFromJSON(jd);
        }
Exemplo n.º 4
0
        private void init()
        {
            lastPacketKey = new PacketKey(0); // is time

            writeThread = new Thread(writeLoop);

            sendQ           = new LinkedList <Packet>();
            writeResetEvent = new AutoResetEvent(false);

            EventBulletin.Subscribe(EventBulletin.Event.CLOSE, (o, e) => { Close(); });

            Task.Delay(0).ContinueWith((t) =>
            {
                connectProcedure();
                running = true;

                beginRead(incommingRead);
                writeThread.Start();
            });
        }
Exemplo n.º 5
0
 public PacketKey(PacketKey other)
 {
     value = other.value;
 }
Exemplo n.º 6
0
 public Packet(ComData d)
 {
     Key  = new PacketKey();
     Data = d;
 }