예제 #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
파일: Program.cs 프로젝트: java02014/Blink
 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);
            }
        }