Example #1
0
 public UdpServer(UdpConfig config, ILoger loger)
 {
     this.Config          = config;
     this.Loger           = loger;
     sendArgsPool         = new EventArgsPool(config.MaxSendEventArgs);
     receiveEventArgsList = new List <SocketAsyncEventArgs>(config.ListenerThreads);
     BufferPool           = new FixedBufferPool(config.MaxFixedBufferPoolSize, config.BufferSize);
 }
Example #2
0
    public static UdpSocket CreatePlatformSpecificSocket <TSerializer> (UdpConfig config) where TSerializer : UdpSerializer, new()
    {
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
        return(UdpSocket.Create <UdpPlatformManaged, TSerializer>(config));
#elif UNITY_IPHONE
        return(UdpSocket.Create <UdpPlatformIOS, TSerializer>(config));
#elif UNITY_ANDROID
        return(UdpSocket.Create <UdpPlatformAndroid, TSerializer>(config));
#else
        throw new System.NotImplementedException("UdpKit doesn't support the current platform");
#endif
    }
Example #3
0
    public static UdpSocket CreatePlatformSpecificSocket <TSerializer> (UdpConfig config) where TSerializer : UdpSerializer, new()
    {
#if UNITY_IPHONE
        return(UdpSocket.Create <UdpPlatformIOS, TSerializer>(config));
#elif UNITY_ANDROID
        return(UdpSocket.Create <UdpPlatformAndroid, TSerializer>(config));
#elif UNITY_WEBPLAYER || UNITY_STANDALONE || UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX
        return(UdpSocket.Create <UdpPlatformManaged, TSerializer>(config));
#else
        throw new NotSupportedException(string.Format("UdpKit doesn't support the platform '{0}'", Application.platform));
#endif
    }
Example #4
0
        static void Main(string[] args)
        {
            DebugMemoryDataCollector coll;
            //PersistenceManagerHandlerMemory<int, LightwaveMessage> pm = null;
            PersistenceManagerHandlerFileSystem <int, LightwaveMessage> pm = null;
            PersistenceClient <int, LightwaveMessage> pc = null;

            mservice = new MicroservicePipeline("PiO", description: "PiO Server");

            mservice
            .AdjustPolicyTaskManagerForDebug()
            .ConfigurationSetFromConsoleArgs(args)
            .AddDebugMemoryDataCollector(out coll)
            .AddChannelIncoming("lightwave", "LightwaveRF UDP traffic", ListenerPartitionConfig.Init(1))
            .AttachUdpListener(UdpConfig.UnicastAllIps(9761)
                               , requestAddress: ("message", "in")
                               , deserialize: (holder) => holder.SetObject(new LightwaveMessage(holder.Blob, (IPEndPoint)holder.Metadata), true))
            .AttachCommand(async(ctx) =>
            {
                //Do nothing
                var debug = pm.ChannelId;
                var rs    = await pc.Create(ctx.Request.Message.Holder.Object as LightwaveMessage);
            }, ("message", "in"))
            //.AttachPersistenceManagerHandlerMemory((LightwaveMessage m) => m.Trans, (s) => int.Parse(s), out pm)
            .AttachPersistenceManagerFileSystem((LightwaveMessage m) => m.Trans, (s) => int.Parse(s), out pm)
            .AttachPersistenceClient(out pc)
            .Revert()
            .AddChannelOutgoing("status", "Outgoing UDP status", SenderPartitionConfig.Init(1))
            .AttachUdpSender(UdpConfig.BroadcastAllIps(44723), serializer: new StatisticsSummaryLogUdpSerializer())
            .Revert()
            .OnDataCollection
            (
                (ctx, ev) =>
            {
                ctx.Outgoing.Process(("status", null, null), ev.Data, 1, ProcessOptions.RouteExternal);
            }
                , DataCollectionSupport.Statistics
            )
            ;

            mservice.StartWithConsole(args: args);
        }
Example #5
0
        public void Init()
        {
            ServerCommandLine.Instance.Init();
            ResControl.Instance.Init();
            NodeControl.Instance.Init();
            EntityContent.Instance.Init();

            IPEndPoint point = UdpConfig.DnsToIPEndPoint(Config.primarilyIp);

            if (point == null)
            {
                Server = new UdpPoint(Config.primarilyPort, false);
            }
            else
            {
                Server = new UdpPoint(point, false);
            }

            m_isBroadcast = Config.isEnableBroadcast;
            //最大存储1000帧指令
            MaxQueueBuffer = 1000;
            //缓存队列计数
            QueueBufferCount = 0;
            //设置一个随机验证值
            LocalNetNode.license = random.Next();
            //新的服务器信息
            HostInfo             = new ServerInfo();
            HostInfo.name        = Config.name;
            HostInfo.description = Config.description;
            //服务端启动时间
            //StartTickTime = RealityTickTime;
            Console.WriteLine("[Server状态机执行初始化]" + IsBroadcast);

            Server.Mgr.OnRequestDataHandle += NetRequestData.OnRequestDataServer;
            Server.Mgr.OnCmdDataHandle     += NetCmdData.OnCmdDataServer;
            Server.Mgr.OnReadBufferHandle  += NetReadBuffer.OnReadBufferServer;
            Server.Mgr.OnRequestCmdHandle  += NetRequestCmd.OnRequestCmdServer;

            //Console.WriteLine(Server.LocalEndPoint);
        }
Example #6
0
        static void Server()
        {
#if DISABLE_AUTO_ACCEPT
            UdpConfig config = new UdpConfig();
            config.AutoAcceptIncommingConnections = false;
#else
            UdpConfig config = new UdpConfig();
#endif
            UdpSocket server = UdpSocket.Create <UdpPlatformManaged, DummySerializer>(config);
            server.Start(new UdpEndPoint(UdpIPv4Address.Localhost, 14000));

            while (true)
            {
                UdpEvent ev = default(UdpEvent);

                while (server.Poll(ref ev))
                {
                    UdpLog.User("Event raised {0}", ev.EventType);

                    switch (ev.EventType)
                    {
                    case UdpEventType.Connected:
                        UdpLog.User("Client connected from {0}, total clients connected: {1}", ev.Connection.RemoteEndPoint, server.ConnectionCount);
                        break;

#if ENABLE_MANUAL_ACCEPT
                    case UdpEventType.ConnectRequest:
                        UdpLog.User("Connection requested from {0}", ev.EndPoint);
                        server.Accept(ev.EndPoint);
                        break;
#endif
                    }
                }

                // Simulate ~60fps game loop
                Thread.Sleep(16);
            }
        }
Example #7
0
 public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port, udpConfig.ReconnectInterval)
 {
 }
Example #8
0
        void IsConnectArgument(CommandLineArgumentParser arguments, ref int valid)
        {
            if (arguments.StartWith("/connect"))
            {
                if (arguments.Has("-t"))
                {
                    ServerInfo info = null;
                    if (arguments.Has("-f"))
                    {
                        foreach (var item in NetControl.Instance.ServerInfoDic)
                        {
                            if (item.Value.isValid)
                            {
                                info = item.Value;
                                NetControl.Instance.TryServerConnectTest(info);
                                valid += 1; return;
                            }
                        }
                        Console.WriteLine("未找到任何服务端");
                        valid += 1; return;
                    }
                    else
                    {
                        CommandLineArgument node = arguments.Get("-t");
                        if (node.Take() != null && node.Take() != "")
                        {
                            string     ip    = node.Take();
                            IPEndPoint point = UdpConfig.StrParseToIp(ip);
                            if (point == null)
                            {
                                point = UdpConfig.DnsToIPEndPoint(ip);
                            }
                            if (point != null)
                            {
                                NetControl.Instance.TryServerConnectTest(point);
                                valid += 1; return;
                            }
                            else
                            {
                                Console.WriteLine("无效的网络地址");
                                valid += 1; return;
                            }
                        }
                    }

                    if (info != null)
                    {
                        NetControl.Instance.TryServerConnectTest(info);
                    }
                    else
                    {
                        Console.WriteLine("未选择任何服务端");
                    }
                    valid += 1;
                    return;
                }
                if (arguments.Has("-c"))
                {
                    ServerInfo info = NetControl.Instance.CurrentConnectHost;
                    if (info != null)
                    {
                        NetControl.Instance.TryCanelConnectHost();
                    }
                    else
                    {
                        Console.WriteLine("未连接任何服务端");
                    }
                    valid += 1; return;
                }
                if (arguments.Has("-f"))
                {
                    foreach (var item in NetControl.Instance.ServerInfoDic)
                    {
                        if (item.Value.isValid)
                        {
                            NetControl.Instance.TryConnectHost(item.Value);
                            valid += 1; return;
                        }
                    }
                    Console.WriteLine("未找到任何服务端");
                    valid += 1; return;
                }
                if (arguments.Has("-i"))
                {
                    ServerInfo info = NetControl.Instance.CurrentConnectHost;
                    if (info != null)
                    {
                        Console.WriteLine("[n]" + info.name + "[d]" + info.description + "[r]" + info.remote + "[is]" + info.isSync + ":" + NodeControl.Instance.LocalPlayer.serial + "" + "[ic]" + info.isConnect + "[iv]" + info.isValid + "[io]" + info.isOvertime + "[nc]" + info.currentConnectNodeCount + "[mc]" + info.maxConnectNodeCount + "[ot]" + (TimeControl.TickTime - info.lastTime) + "ms");
                    }
                    else
                    {
                        Console.WriteLine("未连接任何服务端");
                    }
                    valid += 1;
                }
                Console.WriteLine("输入参考:\n参数 -c 取消当前连接\n参数 -f 连接第一个有效的服务端\n参数 -i 查看当前连接信息\n参数 -t[address] 尝试获取服务端信息");
                valid += 1;
            }
            else
            {
                return;
            }
        }
 /// <summary>Builds a new instance of the MessageTransmitterConfig class</summary>
 public MessageTransmitterConfig()
 {
     Udp = new UdpConfig();
     Tcp = new TcpConfig();
 }
Example #10
0
 public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port, udpConfig.ReconnectInterval)
 {
     connectionCheckTimeout = udpConfig.ConnectionCheckTimeout;
 }
Example #11
0
 public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port)
 {
     udp = new UdpClient(IpAddress, Port);
 }
Example #12
0
 public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port)
 {
     udp = new UdpClient(IpAddress, Port);
 }
Example #13
0
        static void Server()
        {
            #if DISABLE_AUTO_ACCEPT
            UdpConfig config = new UdpConfig();
            config.AutoAcceptIncommingConnections = false;
            #else
            UdpConfig config = new UdpConfig();
            #endif
            UdpSocket server = UdpSocket.Create<UdpPlatformManaged, DummySerializer>(config);
            server.Start(new UdpEndPoint(UdpIPv4Address.Localhost, 14000));

            while (true) {
                UdpEvent ev;

                while (server.Poll(out ev)) {
                    UdpLog.User("Event raised {0}", ev.EventType);

                    switch (ev.EventType) {
                        case UdpEventType.Connected:
                            UdpLog.User("Client connected from {0}", ev.Connection.RemoteEndPoint);
                            break;

            #if ENABLE_MANUAL_ACCEPT
                        case UdpEventType.ConnectRequest:
                            UdpLog.User("Connection requested from {0}", ev.EndPoint);
                            server.Accept(ev.EndPoint);
                            break;
            #endif
                    }
                }

                // Simulate ~60fps game loop
                Thread.Sleep(16);
            }
        }