static void Client() { UdpSocket client = UdpSocket.Create <UdpPlatformManaged, DummySerializer>(); client.Start(UdpEndPoint.Any); client.Connect(new UdpEndPoint(UdpIPv4Address.Localhost, 14000)); while (true) { UdpEvent ev = default(UdpEvent); while (client.Poll(ref ev)) { UdpLog.User("Event raised {0}", ev.EventType); switch (ev.EventType) { case UdpEventType.Connected: UdpLog.User("Connected to server at {0}", ev.Connection.RemoteEndPoint); break; #if DISABLE_AUTO_ACCEPT case UdpEventType.ConnectFailed: UdpLog.User("Connection to {0} failed", ev.EndPoint); break; #endif } } // Simulate ~60fps game loop Thread.Sleep(16); } }
static void Server() { UdpSocket socket = UdpSocket.Create <UdpPlatformManaged, Serializer>(); socket.Start(new UdpEndPoint(UdpIPv4Address.Localhost, 14000)); EventLoop(socket); }
public void Start(CClientNetworkCtrl clientNetworkCtrl) { if (server == null) { UdpLog.Writer writer = new UdpLog.Writer(DebugImplement); //(lvl, s) => Log.info("P2PClientNetWork", s) UdpLog.SetWriter(writer); try { server = UdpSocket.Create <UdpPlatformManaged, P2PSerializer>(); } catch (Exception e) { Log.info(e, "P2PClientNetWork Start#Exception happened"); //MonoBehaviour.print(e); } //sever and client. ConnectServer(clientNetworkCtrl); /* * localPort = clientNetworkCtrl.LocalPort; * UdpEndPoint serverPoint = new UdpEndPoint(UdpIPv4Address.Any, (ushort)localPort); * server.Start(serverPoint); * IPAddress ipaddr = IPAddress.Parse (clientNetworkCtrl.ServerIP); * hostUser.ProxyServer = new IPEndPoint( ipaddr, clientNetworkCtrl.ServerPort ); * * UdpIPv4Address address = UdpIPv4Address.Parse(clientNetworkCtrl.ServerIP); * UdpEndPoint endp = new UdpEndPoint(address, (ushort)clientNetworkCtrl.ServerPort); * server.Connect( endp ); * * Log.info("P2PClientNetWork", "P2PClientWork Start, UdpPort:" + localPort + " ServerIP:" + clientNetworkCtrl.ServerIP.ToString() + " ProxyServer address:" + endp.ToString()); * CtrlOwner = clientNetworkCtrl;*/ } }
static void Server(int count) { UdpSocket[] sockets = new UdpSocket[count]; for (int i = 0; i < count; ++i) { sockets[i] = UdpSocket.Create <UdpPlatformManaged, DummySerializer>(); sockets[i].Start(new UdpEndPoint(UdpIPv4Address.Localhost, (ushort)(14000 + i))); } UdpSocketMultiplexer multiplexer = UdpSocket.CreateMultiplexer(sockets); while (true) { UdpEvent ev; UdpSocket socket; while (multiplexer.Poll(out ev, out socket)) { UdpLog.User("Event raised {0}", ev.EventType); switch (ev.EventType) { case UdpEventType.Connected: UdpLog.User("Client connected from {0}", ev.Connection.RemoteEndPoint); break; } } // Simulate ~60fps game loop Thread.Sleep(16); } }
static void Client(int count) { // random object used to generate random port Random rnd = new Random(); UdpSocket client = UdpSocket.Create <UdpPlatformManaged, DummySerializer>(); client.Start(UdpEndPoint.Any); client.Connect(new UdpEndPoint(UdpIPv4Address.Localhost, (ushort)(14000 + rnd.Next(count)))); while (true) { UdpEvent ev; while (client.Poll(out ev)) { UdpLog.User("Event raised {0}", ev.EventType); switch (ev.EventType) { case UdpEventType.Connected: UdpLog.User("Connected to server at {0}", ev.Connection.RemoteEndPoint); break; } } // Simulate ~60fps game loop Thread.Sleep(16); } }
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 }
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 }
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); } }
public Server() { socket = UdpSocket.Create <UdpPlatformManaged, ChatSerializer>(); socket.Start(new UdpEndPoint(UdpIPv4Address.Localhost, 14000)); clients = new List <UdpConnection>(); }
public Client() { socket = UdpSocket.Create <UdpPlatformManaged, ChatSerializer>(); socket.Start(UdpEndPoint.Any); socket.Connect(new UdpEndPoint(UdpIPv4Address.Localhost, 14000)); }
public SocketObject() { socket = UdpSocket.Create <UdpPlatformManaged, Serializer>(new UdpConfig { SimulatedLoss = 0.25f, ConnectionTimeout = 100000000, PingTimeout = 10, ConnectionLimit = -1 }); }