ListenTcp() 공개 메소드

public ListenTcp ( int maxWaitingQueue ) : void
maxWaitingQueue int
리턴 void
예제 #1
0
파일: Main.cs 프로젝트: mk8/modbus-sharp
        public static int ServerTestMulti(string listenAddress, int port, bool debug)
        {
            ModbusCore core = new ModbusCore (listenAddress, port);
            core.Debug = debug;

            if (core.MappingNew (500, 500, 500, 500)) {
                Console.WriteLine ("Failed to allocate the mapping.");
                return -1;
            }

            // Initialization for testing
            for (int i = 0; i < 500; ++i) {
                core.RegisterRWSigned[i] = (short)(1000+i);
                core.RegisterInputSigned[i] = (short)i;
            }

            core.ListenTcp (10);
            while (true) {
                core.AcceptTcp ();

                HandleModbusQuery mq = new HandleModbusQuery(core);
                Thread thread = new Thread(new ThreadStart(mq.HandleRequests));
                thread.Start ();
            }

            core.MappingDispose ();
            core.Close ();
            core.Dispose ();

            return 0;
        }
예제 #2
0
파일: Main.cs 프로젝트: mk8/modbus-sharp
        public static int ServerTest(string listenAddress, int port, bool debug)
        {
            ModbusCore core = new ModbusCore (listenAddress, port);
            core.Debug = debug;

            if (core.MappingNew (500, 500, 500, 500)) {
                Console.WriteLine ("Failed to allocate the mapping.");
                return -1;
            }

            // Initialization for testing
            for (int i = 0; i < 500; ++i) {
                core.RegisterRWSigned[i] = (short)(1000+i);
                core.RegisterInputSigned[i] = (short)i;
            }

            core.ListenTcp (1);
            while (true) {
                core.AcceptTcp ();

                while (true) {
                    byte[] query;
                    try {
                        query = core.Receive ();
                        core.Reply (query);
                    } catch {
                        // Connection closed by the client or error
                        break;
                    }
                }
            }

            core.MappingDispose ();
            core.Close ();
            core.Dispose ();

            return 0;
        }