public bool Connect() { if (Connected) { return(true); } try { _darkRiftClient.Connect(_ip, Port, IpVersion); if (Connected) { Debug.Log("Connected to " + _ip + " on port " + Port + " using " + IpVersion + "."); return(true); } Debug.Log("Connection failed to " + _ip + " on port " + Port + " using " + IpVersion + "."); return(false); } catch (Exception e) { Debug.Log(e.Message + " - " + e.StackTrace); return(false); } }
public bool Connect(IPAddress ip, ushort port, IPVersion ipVersion) { if (Connected) { return(true); } try { _darkRiftClient.Connect(ip, port, ipVersion); if (Connected) { Debug.Log("Connected to " + ip + " on port " + port + " using " + ipVersion + "."); return(true); } Debug.Log("Connection failed to " + ip + " on port " + port + " using " + ipVersion + "."); return(false); } catch (Exception e) { Debug.Log(e.Message + " - " + e.StackTrace); return(false); } }
public void GivenClientsThatFailToConnect(int numberOfClients) { for (int i = 0; i < numberOfClients; i++) { DarkRiftClient client = new DarkRiftClient(); try { client.Connect( new BichannelClientConnection( IPAddress.Loopback, 4296, // Don't want to be able to connect so any port is fine true ) ); Assert.Fail("Did not expect client to connect successfully."); } catch (SocketException) { // Expected } world.AddClient(client); } }
public void WhenAClientConnectsAndImmedtiatelySendsAMessages() { DarkRiftClient client = new DarkRiftClient(); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write("Hello"); using Message message = Message.Create(0, writer); client.Connect( new BichannelClientConnection( IPAddress.Loopback, world.GetServer(0).ClientManager.Port, world.GetServer(0).NetworkListenerManager.GetNetworkListenersByType <AbstractBichannelListener>()[0].UdpPort, true ) ); bool success = client.SendMessage(message, SendMode.Reliable); Assert.IsTrue(success); } world.AddClient(client); #if DEBUG // We've just requested a load of objects that wont be returned until we close // UDP receive TCP receive in client; TCP receive in server performanceSteps.ExpectedUnaccountedForSocketAsyncEventArgs += 3; #endif messageAssertions.ExpectMessageOnServer(new ReceivedMessage("Hello", client.ID, 0, 0, SendMode.Reliable)); }
static void Main(string[] args) { MLAPI.SyncTypes.Add(1, typeof(House)); DarkRiftClient.MessageReceived += MessageReceived; DarkRiftClient.Connect(System.Net.IPAddress.Loopback, 4296, IPVersion.IPv4); Console.ReadLine(); }
/// <summary> /// Connect a client with our client connection to the given server. /// </summary> /// <returns>The created client.</returns> private DarkRiftClient ConnectClient(DarkRiftServer server) { NetworkClientConnection1 connection = new NetworkClientConnection1(IPAddress.Loopback, server.NetworkListenerManager.GetNetworkListenerByName("ListenerUnderTest").Port); DarkRiftClient client = new DarkRiftClient(); client.Connect(connection); return(client); }
/// <summary> /// Connects to a remote server. /// </summary> /// <param name="ip">The IP address of the server.</param> /// <param name="port">The port of the server.</param> public void Connect(IPAddress ip, int port, IPVersion ipVersion) { enetConnnection = new EnetClientConnection(ip.ToString(), port); client.Connect(enetConnnection); //Client.Connect(ip, port, ipVersion); if (ConnectionState == ConnectionState.Connected) { Debug.Log("Connected to " + ip + " on port " + port + " using " + ipVersion + "."); } else { Debug.Log("Connection failed to " + ip + " on port " + port + " using " + ipVersion + "."); } }
public bool Connect() { if (client.ConnectionState == DarkRift.ConnectionState.Connecting) { return(false); } if (client.ConnectionState == DarkRift.ConnectionState.Connected) { return(true); } try { client.Connect(IPAddress.Parse("127.0.0.1"), 4296, false); client.MessageReceived += OnMessageReceived; return(true); } catch (Exception) { } return(false); }
public bool Connect() { if (client.ConnectionState == DarkRift.ConnectionState.Connecting) { return(false); } if (client.ConnectionState == DarkRift.ConnectionState.Connected) { return(true); } try { client.Connect(IPAddress.Parse("148.255.110.94"), 4296, DarkRift.IPVersion.IPv4); return(true); } catch (Exception) { } return(false); }
private DarkRiftClient GetNewClient() { if (this.client == null) { var client = new DarkRiftClient(); var ep = IPEndPoint.Parse(connectionAddress); try { client.Connect(ep.Address, ep.Port, IPVersion.IPv4); if (client.ConnectionState == ConnectionState.Connected) { this.client = client; } } catch (Exception e) { Console.WriteLine(e.ToString()); } } return(this.client); }
public void GivenConnectedClientsOverIPv6(int numberOfClients) { for (int i = 0; i < numberOfClients; i++) { DarkRiftClient client = new DarkRiftClient(); client.Connect( new BichannelClientConnection( IPAddress.IPv6Loopback, world.GetServer(0).ClientManager.Port, world.GetServer(0).NetworkListenerManager.GetNetworkListenersByType <AbstractBichannelListener>()[0].UdpPort, true ) ); world.AddClient(client); #if DEBUG // We've just requested a load of objects that wont be returned until we close // UDP receive TCP receive in client; TCP receive in server performanceSteps.ExpectedUnaccountedForSocketAsyncEventArgs += 3; #endif } }