Exemplo n.º 1
0
 static async Task Main(string[] args)
 {
     mServer = BeetleX.SocketFactory.CreateTcpServer <Program>();
     mServer.Options.DefaultListen.Host = mHost;
     mServer.Options.DefaultListen.Port = 9090;
     mServer.Open();
     mClient             = SocketFactory.CreateClient <AsyncTcpClient>(mHost, 9090);
     mClient.DataReceive = (c, e) =>
     {
         if (e.Stream.ToPipeStream().TryReadLine(out string line))
         {
             Console.WriteLine("receive:" + line);
             Enter();
         }
     };
     Enter();
     await Task.Delay(-1);
 }
Exemplo n.º 2
0
        public void Open()
        {
            try
            {
                mRouteCenter = new RouteCenter();
                mRouteCenter.Register(this);
                if (!System.IO.Directory.Exists(UNIT_TESTCASE_PATH))
                {
                    System.IO.Directory.CreateDirectory(UNIT_TESTCASE_PATH);
                }
                mServerClient       = BeetleX.ServerFactory.CreateTcpClient <Network.ClientPacket>(ServerHost, ServerPort);
                mNodeServer         = BeetleX.ServerFactory.CreateTcpServer <NodeApp, Network.Packet>(mNetConfig);
                mNodeServer.Handler = this;
                while (!mNodeServer.Open())
                {
                    mNodeServer.Config.Port++;
                }
                Loger.Process(LogType.INFO, "Note network start!");
                LoadProcessAgent();
                Loger.Process(LogType.INFO, "Note load unittest completed!");
                mServerClient.ClientError      = OnServerError;
                mServerClient.ConnectedServer  = OnServerConnect;
                mServerClient.Packet.Completed = OnPacketCompleted;
                if (mServerClient.Connect())
                {
                    Loger.Process(LogType.INFO, "Note connect to {0}", ServerHost);
                }
                else
                {
                    Loger.Process(LogType.ERROR, "Note connect to {0} error {1}", ServerHost, mServerClient.LastError.Message);
                }

                this.Performance.Open();
            }
            catch (Exception e_)
            {
                Loger.Process(LogType.INFO, "Note network start error {0}", e_.Message);
            }
            if (mPingTimer != null)
            {
                mPingTimer.Dispose();
            }
            mPingTimer = new System.Threading.Timer(PingServer, this, 1000, 1000);
        }
Exemplo n.º 3
0
        public void Open()
        {
            try
            {
#if DOTNET_CORE
                mIsLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
#endif
                IPacket   packet    = new Protocols.Packet();
                NetConfig netconfig = new NetConfig();

                netconfig.Port = Port;
                netconfig.Host = Host;
                mServer        = ServerFactory.CreateTcpServer(netconfig, this, packet);
                while (!mServer.Open())
                {
                    Port++;
                    netconfig.Port++;
                    if (Port > 60000)
                    {
                        Status = NodeStatus.Error;
                        Loger.Process(LogType.ERROR, "node create server error!");
                        return;
                    }
                }
                mBroadcastListen          = new NodeBroadcastListen(this.Cluster, Host, Port, ID, TokenKey);
                mBroadcastListen.Loger    = Loger;
                mBroadcastListen.Discover = OnDiscoverNode;
                mBroadcastListen.Open();
                mPingNodeTimer = new System.Threading.Timer(OnPingRemoteNode, null, 1000, 1000);
                Loger.Process(LogType.INFO, "[{0}] Node Start {1}@{2}", ID, Host, Port);
                DefaultEventSubscriber  = Register <EventSubscriber>("NODE_DEFAULT_EVENTSUBSCRIBER_" + ID);
                DefaultSwitchSubscriber = new SwitchSubscriber(this);
                Status = NodeStatus.Start;
            }
            catch (Exception e_)
            {
                Status = NodeStatus.Error;
                Loger.Process(LogType.ERROR, "node start error {0}!", e_.Message);
            }
        }