예제 #1
0
파일: Main.cs 프로젝트: blindsight/Talker
		public static void Main(string[] args)
		{
			// Check if the config file is correctly loaded
			if (System.Configuration.ConfigurationManager.AppSettings.Count == 0) {
				Console.WriteLine("ERROR: config file not loaded");
				return;
			}

			int AddressPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["port"]);
			int webSocketPort = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["webSocketPort"]);

			//TODO: error message port must be above 1024
			tcpListener = new TcpListener(IPAddress.Any, AddressPort);
			listenThread = new Thread(new ThreadStart(ListenForClients));
			listenThread.Start();
			System.Reflection.Assembly CurrentServer = System.Reflection.Assembly.GetExecutingAssembly();
			string ProductVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(CurrentServer.Location).ProductVersion;
			DateTime CurrentDateTime = DateTime.Now;

			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("{0} {1} server booting on {2} at {3}", CurrentServer.GetName().Name, ProductVersion, CurrentDateTime.ToLongDateString(), CurrentDateTime.ToLongTimeString());
			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("Node Name : {0}", System.Environment.MachineName);

		
			//Console.WriteLine("Running On : {0} {1}", (Is64) ? "x86_64": "x86" ,System.Environment.OSVersion.ToString());
			Console.WriteLine("Started server at " + AddressPort);

			SuperSocket.SocketBase.Config.RootConfig r = new SuperSocket.SocketBase.Config.RootConfig();

			SuperSocket.SocketBase.Config.ServerConfig s = new SuperSocket.SocketBase.Config.ServerConfig();
			s.Name = "SuperWebSocket";
			s.Ip = "Any";
			s.Port = webSocketPort;
			s.Mode = SocketMode.Tcp;

			SuperSocket.SocketEngine.SocketServerFactory f = new SuperSocket.SocketEngine.SocketServerFactory();


			if (ws != null)
			{
				ws.Stop();
				ws = null;
			}

			ws = new WebSocketServer();
			ws.Setup(r, s, f);
			ws.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(ws_SessionClosed);
			ws.NewSessionConnected += new SessionHandler<WebSocketSession>(ws_NewSessionConnected);
			ws.NewMessageReceived += new SessionHandler<WebSocketSession, string>(ws_NewMessageReceived);
			ws.NewDataReceived += new SessionHandler<WebSocketSession, byte[]>(ws_NewDataReceived);
			ws.Start();

			Console.WriteLine("------------------------------------------------------------------------------");
			Console.WriteLine("Booted with PID {0}", System.Diagnostics.Process.GetCurrentProcess().Id);
			Console.WriteLine("------------------------------------------------------------------------------");
		}
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm = null;

            if (_is_connect)
            {
                NfcApi.SCardReleaseContext(_hContext);
            }

            server_ssl.Stop();
        }
예제 #3
0
        static void Main(string[] args)
        {
            MainModel.Snakes = Snakes;
            Fruit fruit = createFruit(FruitId);

            Fruits.AddOrUpdate("0", fruit, (key, oldValue) => fruit);
            MainModel.Fruits = Fruits;

            wsServer = new SuperWebSocket.WebSocketServer();
            int port = 8080;

            wsServer.Setup(port);
            wsServer.NewSessionConnected += WsServer_NewSessionConnected;
            wsServer.NewMessageReceived  += wsServer_NewMessageReceived;
            wsServer.NewDataReceived     += wsServer_NewDataReceived;
            wsServer.SessionClosed       += wsServer_SessionClosed;
            wsServer.Start();
            Console.WriteLine("Server is running on port: " + port + ". Enter to exit...");
            Console.Read();
            wsServer.Stop();
        }
예제 #4
0
        static int Main(string[] args)
        {
            Console.BufferHeight = 10000;
            Console.BufferWidth = 110;
            Console.WindowWidth = 110;
            Console.WindowHeight = 60;


            var reader = new StreamReader("Config.js");
            var cfgFile = reader.ReadToEnd();
            reader.Close();

            serverInfo = JsonConvert.DeserializeObject<ServerInfo>(cfgFile);
            serverInfo.Started = DateTime.Now;

            var callbackClients = serverInfo.CallbackClients;
            
            ComPortConfigs = new List<SerialConfig>();
            
            foreach (var cfg in serverInfo.Configs)
            {
                var config = AddPort(cfg, cfg.AutoConnect);
            }

            Log("HTTP: " + serverInfo.HttpInterface);
            httpServer = new SmallHttpServer(serverInfo.HttpPort);
            httpServer.OnConnect += httpServer_OnConnect;
            httpServer.OnData += httpServer_OnData;
            httpServer.Start();

            Log("WEB-SOCKET: " + serverInfo.SocketInterface);
            socketServer = new WebSocketServer();
            socketServer.Setup(serverInfo.SocketPort);
            socketServer.NewMessageReceived += socketServer_NewMessageReceived;
            socketServer.SessionClosed += socketServer_SessionClosed;
            socketServer.NewSessionConnected += socketServer_NewSessionConnected;
            socketServer.Start();

            /*
            serial = new UART.Serial(comPort, comPortSpeed);
            Log("COM: " + comPort + " " + comPortSpeed);
            serial.OnReceive += serial_OnReceive;
            serial.OnError += serial_OnError;
            serial.OnStateChange += serial_OnStateChange;
            serial.Connect();
            */

            tcpService = new SmallTcpService();
            tcpService.OnData += tcpService_OnData;
            tcpService.OnClientState += tcpService_OnClientState;
            tcpService.Start(callbackClients.ToArray());

            //CallbackHeartBeatTimer = new Timer(


            Thread.CurrentThread.Join();
                        
            foreach (var serial in Serials)
            {
                if (serial.Value != null)
                {
                    serial.Value.Close();
                }
            }

            httpServer.Close();
            socketServer.Stop();
            tcpService.Close();

            return 0;
        }
예제 #5
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm = null;

            server_ssl.Stop();
        }
예제 #6
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Press any key to start the server!");

            //Console.ReadKey();
            //Console.WriteLine();

            //var bootstrap = BootstrapFactory.CreateBootstrap();

            //if (!bootstrap.Initialize())
            //{
            //    Console.WriteLine("Failed to initialize!");
            //    Console.ReadKey();
            //    return;
            //}

            //WebSocketServer server = Enumerable.First<IWorkItem>(bootstrap.AppServers) as WebSocketServer;
            //server.NewSessionConnected += wsServer_NewSessionConnected;
            //server.SessionClosed += wsServer_SessionClosed;
            //server.NewDataReceived += wsServer_NewDataReceived;
            //server.NewMessageReceived += wsServer_NewMessageReceived;

            //var result = bootstrap.Start();

            //Console.WriteLine("Start result: {0}!", result);

            //if (result == StartResult.Failed)
            //{
            //    Console.WriteLine("Failed to start!");
            //    Console.ReadKey();
            //    return;
            //}

            //Console.WriteLine("Press key 'q' to stop it!");

            //while (Console.ReadKey().KeyChar != 'q')
            //{
            //    Console.WriteLine();
            //    continue;
            //}

            //Console.WriteLine();

            ////Stop the appServer
            //bootstrap.Stop();


            ServerConfig cfg = new ServerConfig()
            {
                Port = 12012,
                Ip   = "Any",
                Mode = SuperSocket.SocketBase.SocketMode.Tcp,
                //ReceiveBufferSize = 100* 1024,
                //SendBufferSize = 2048 * 1024,
                MaxRequestLength = 2048 * 1024,
                //MaxConnectionNumber = 20
            };

            WebSocketServer wsServer = new WebSocketServer();

            if (!wsServer.Setup(cfg))
            {
                Console.WriteLine("Failed to setup!");
                Console.ReadKey();
                return;
            }

            wsServer.NewSessionConnected += wsServer_NewSessionConnected;
            wsServer.SessionClosed       += wsServer_SessionClosed;
            wsServer.NewDataReceived     += wsServer_NewDataReceived;
            wsServer.NewMessageReceived  += wsServer_NewMessageReceived;



            if (!wsServer.Start())
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the appServer
            wsServer.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }