示例#1
0
        static void Main(string[] args)
        {
            mServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                IPAddress  HostIp = IPAddress.Any;
                IPEndPoint iep    = new IPEndPoint(HostIp, 2626);
                BlinkLog.I("Start Server Socket...");
                mServer.Bind(iep);
                mServer.Listen(Int32.MaxValue);
                mThread = new Thread(Run);
                mThread.Start();
            }
            catch (Exception)
            {
                BlinkLog.E("Start Server Error.");
            }


            BlinkLog.I("=========PRESS ANY KEY TO EXIT==========");
            Console.ReadKey();

            IsExit = true;

            if (mThread != null)
            {
                mThread.Interrupt();
            }
            mServer.Dispose();
            mServer.Close();
        }
示例#2
0
        public void Run()
        {
            int err = 0;

            while (!mQuit)
            {
                ReceivePacket packet;
                try
                {
                    // Receive head
                    packet = mReceiver.ReceiveHead();

                    // Adjust Stream
                    packet.AdjustStream();

                    // Post Start
                    mDelivery.PostReceiveStart(packet);

                    // Receive entity
                    bool status = mReceiver.ReceiveEntity(packet, mDelivery);

                    // Adjust Result value form stream
                    packet.AdjustPacket();

                    // Post End
                    mDelivery.PostReceiveEnd(packet, status);
                }
                catch (Exception e)
                {
                    if (err > 3)
                    {
                        mBlinkConn.Send("dasds");
                    }
                    err++;
                    BlinkLog.E(e.ToString());
                }
                finally
                {
                    sleepSomeTime();
                }
            }
        }
示例#3
0
 static void Run()
 {
     while (!IsExit)
     {
         try
         {
             BlinkLog.I("Server Socket Accept...");
             Socket socket = mServer.Accept();
             BlinkLog.V("New Client Socket.");
             BlinkConn conn = Utils.bindBlink(socket);
             conn.GetResource().ClearAll();
             mBlinkConn.Add(conn);
             BlinkLog.V("Socket To BlinkConn OK.");
         }
         catch (Exception e)
         {
             BlinkLog.E(e.ToString());
         }
     }
 }
示例#4
0
        static void Send(string str)
        {
            try
            {
                FileInfo info = new FileInfo(str);
                if (info.Exists)
                {
                    mBlinkConn.Send(info, new SendCallBack());
                }

                else
                {
                    mBlinkConn.Send(str);
                    BlinkLog.I("Send String To Server.");
                }
            }
            catch (Exception e)
            {
                BlinkLog.E(e.Message);
            }
        }