コード例 #1
0
ファイル: Program.cs プロジェクト: fayca121/MoreBoxShare
        public static void Main(string[] args)
        {
            //chargement de la configuration du server
            settings = new Config();

            //configuration du logging
            InitLogging();

            //configuration du serveur
            server=new NetServer();
            server.OnClientAccepted+=server_OnClientAccepted;
            server.OnClientConnected+= server_OnClientConnected;
            server.OnClientDisconnected+= server_OnClientDisconnected;
            server.OnClientRejected+= server_OnClientRejected;

            server.OnReceived += server_OnReceived;
            server.OnStarted+= server_OnStarted;
            server.OnStopped+=server_OnStopped;

            server.TickRate = 1000;

            // configuration du port
            serialPort = new SerialPort { BaudRate = settings.BaudRate,
                DataWidth = settings.DataWidth,
                Port = settings.Port,
                StopBits = settings.StopBits,
                ParityBits = settings.ParityBits,
                Priority = ThreadPriority.Highest };

            serialPort.Received += serialPort_Received;
            serialPort.Connected += serialPort_Connected;

            if (!serialPort.Open())
            {
                logger.Error("Le port est occupé");
                Console.Write("Press any key to exit . . . ");
                Console.ReadKey(true);
                return;
            }
            try
            {
                server.Start(IPAddress.Parse(settings.Server),
                             settings.ServerPort,settings.Capacity);
                if(server.IsOnline)
                {
                    running=new Thread(Run);
                    running.Start();
                    running.Join();
                }
            }
            catch(Exception e)
            {
                logger.Error(e.Message);
            }
            finally
            {
                Console.Write("Press any key to exit . . . ");
                Console.ReadKey(true);
            }
        }
コード例 #2
0
        void MoreBoxClientFormLoad(object sender, EventArgs e)
        {
            Config settings=new Config();
            //initialisation du serial port
            serialPort = new SerialPort { BaudRate = settings.BaudRate,
                DataWidth = settings.DataWidth,
                StopBits = settings.StopBits,
                ParityBits = settings.ParityBits,
                Port = settings.Port,
                Delay = 300 };

            serialPort.Received += serialPort_Received;
            serialPort.Connected += serialPort_Connected;
            messages=new StringBuilder();

            //initialisation du client
            client = new NetClient();
            client.OnDisconnected += client_OnDisconnected;
            client.OnReceived += client_OnReceived;
            client.OnConnected += client_OnConnected;
        }