Client InterfaceDelta Engine Documentation
Provides the networking client functionality to send and receive any data object. View code on GitHub

Namespace: DeltaEngine.Networking
Assembly: DeltaEngine.Networking (in DeltaEngine.Networking.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public interface Client : IDisposable

The Client type exposes the following members.

Methods

  NameDescription
Public methodConnect
Public methodSend
Top
Properties

  NameDescription
Public propertyIsConnected
Public propertyTargetAddress
Public propertyUniqueID
Top
Events

  NameDescription
Public eventConnected
Public eventDataReceived
Public eventDisconnected
Top
Remarks

Tests: DeltaEngine.Networking.Tests.ClientTests
Examples

6 unit tests call DeltaEngine.Networking.Client
[Test]
public void ConnectToServer()
{
    var server = new MockServer();
    using (var client = new MockClient(server))
    {
        client.Connect("localhost", 1);
        Assert.IsTrue(client.IsConnected);
    }
}
[Test]
public void SendTestMessageWithoutServerShouldNotCrash()
{
    using (var client = new MockClient(null))
    {
        Assert.IsFalse(client.IsConnected);
        client.Send(new TextMessage(""));
    }
}
[Test]
public void ConvertBinaryDataToArray()
{
    var server = new MockServer();
    Assert.IsNull(server.LastMessage);
    var client = new MockClient(server);
    client.Connect("localhost", 1);
    client.Send(new TextMessage("Hi"));
    var serverMessage = server.LastMessage as TextMessage;
    byte[] byteArray = BinaryDataExtensions.ToByteArrayWithLengthHeader(serverMessage);
    int classNameLength = "TestMessage".Length + StringLengthByte;
    int textLength = "Hi".Length + StringLengthByte + StringIsNullBooleanByte;
    Assert.AreEqual(LengthOfNetworkMessage + LengthOfDataVersion + classNameLength + textLength,
        byteArray.Length);
}
See Also