Show / Hide Table of Contents

    Class SocketerClient

    Simple socket client which uses a generic length-type-data protocol. Chunk format(everything in little-endian order) : uint32_t data_length; uint8_t data[data_length]; NOTE! The code assumes you are running on a little-endian system.

    Inheritance
    Object
    SocketerClient
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Microsoft.MixedReality.SpectatorView
    Assembly: cs.temp.dll.dll
    Syntax
    public class SocketerClient

    Constructors

    SocketerClient(SocketerClient.Protocol, Int32)

    Creates a Socker that waits for packets or connections. Waits for the other Socketer to connect to it. TCP Socketers can still SendNetworkMessage after a connection. UDP Listeners are not able to SendNetworkMessage. Does not need to have a Host specified. Listeners may listen to multiple Senders. TCP Listeners, when calling SendNetworkMessage, will send to every connected Sender. You must call Start to begin.

    Declaration
    public SocketerClient(SocketerClient.Protocol protocol, int port)
    Parameters
    Type Name Description
    SocketerClient.Protocol protocol

    Underlying protocol to use. Each has advantages and disadvantages.

    Int32 port

    The port to use. Suggested values are between 10000 and 40000, and must agree with the Socketer on the other end.

    SocketerClient(SocketerClient.Protocol, String, Int32)

    Creates a Socketer that sends packets or initiates connections. Actively tries to connect/send to the other Socketer. TCP Socketers can still receive messages. UDP Senders cannot. Must have a Host specified. May only send to one listening Socketer. You must call Start to begin.

    Declaration
    public SocketerClient(SocketerClient.Protocol protocol, string host, int port)
    Parameters
    Type Name Description
    SocketerClient.Protocol protocol

    Underlying protocol to use. Each has advantages and disadvantages.

    String host

    The IP address to connect or send packets to.

    Int32 port

    The port to use. Suggested values are between 10000 and 40000, and must agree with the Socketer on the other end.

    Properties

    Host

    The IP address to connect or send packets to. Only populated for senders.

    Declaration
    public string Host { get; }
    Property Value
    Type Description
    String

    OutputQueueLength

    Declaration
    public static int OutputQueueLength { get; }
    Property Value
    Type Description
    Int32

    Port

    The port to use. Suggested values are between 10000 and 40000, and must agree.

    Declaration
    public int Port { get; }
    Property Value
    Type Description
    Int32

    SocketDirection

    Whether this object should listen for incoming connections/packets, or send them. TCP Socketers are able to both send and recieve once a connection is intitiated.

    Declaration
    public SocketerClient.ProtocolDirection SocketDirection { get; }
    Property Value
    Type Description
    SocketerClient.ProtocolDirection

    SocketProtocol

    The protocol to use: TCP or UDP.

    Declaration
    public SocketerClient.Protocol SocketProtocol { get; }
    Property Value
    Type Description
    SocketerClient.Protocol

    SuppressUDPHeaders

    This is a special case property that you probably don't have to touch. It removes socketer's own headers that are layered on top of UDP (it does not affect TCP). The effect is that the type parameter on SendNetworkMessage is ignored, which can be helpful if you wish to implement other protocols (like Open Sound Control) on top of Socketer.

    Declaration
    public bool SuppressUDPHeaders { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    CreateListener(SocketerClient.Protocol, Int32)

    Creates a Socker that waits for packets or connections. Waits for the other Socketer to connect to it. TCP Socketers can still SendNetworkMessage after a connection. UDP Listeners are not able to SendNetworkMessage. Does not need to have a Host specified. Listeners may listen to multiple Senders. TCP Listeners, when calling SendNetworkMessage, will send to every connected Sender.

    Declaration
    public static SocketerClient CreateListener(SocketerClient.Protocol protocol, int port)
    Parameters
    Type Name Description
    SocketerClient.Protocol protocol

    Underlying protocol to use. Each has advantages and disadvantages.

    Int32 port

    The port to use. Suggested values are between 10000 and 40000, and must agree with the Socketer on the other end.

    Returns
    Type Description
    SocketerClient

    CreateSender(SocketerClient.Protocol, String, Int32)

    Creates a Socketer that sends packets or initiates connections. Actively tries to connect/send to the other Socketer. TCP Socketers can still receive messages. UDP Senders cannot. Must have a Host specified. May only send to one listening Socketer.

    Declaration
    public static SocketerClient CreateSender(SocketerClient.Protocol protocol, string host, int port)
    Parameters
    Type Name Description
    SocketerClient.Protocol protocol

    Underlying protocol to use. Each has advantages and disadvantages.

    String host

    The IP address to connect or send packets to.

    Int32 port

    The port to use. Suggested values are between 10000 and 40000, and must agree. with the Socketer on the other end.

    Returns
    Type Description
    SocketerClient

    Disconnect(Int32)

    Disconnects the client

    Declaration
    public void Disconnect(int sourceId)
    Parameters
    Type Name Description
    Int32 sourceId

    GetLocalIPAddress()

    Gets the IP of this machine. Suitable for use as a Host on another Socketer.

    Declaration
    public static string GetLocalIPAddress()
    Returns
    Type Description
    String

    The host of the local Socketer.

    SendNetworkMessage(Byte[], Int32)

    Sends a byte array to the other side. Works for all Socketers except UDP Listeners. If the other Socketer is not listening, the messages are lost.

    Declaration
    public void SendNetworkMessage(byte[] message, int sourceId = 0)
    Parameters
    Type Name Description
    Byte[] message

    Message contents.

    Int32 sourceId

    SendNetworkMessage(String, Int32)

    Sends a string to the other side. Works for all Socketers except UDP Listeners. If the other Socketer is not listening, the messages are lost.

    Declaration
    public void SendNetworkMessage(string message, int sourceId = 0)
    Parameters
    Type Name Description
    String message

    Message contents.

    Int32 sourceId

    Start()

    Begins either listening or sending.

    Declaration
    public void Start()

    Stop()

    Stops listening or sending. This should be called when you are done.

    Declaration
    public void Stop()

    StopConnectionAttempts()

    Call to prevent additional attempts at connecting. Note: if no connection has been established, calling this function will prevent establishing a connection.

    Declaration
    public void StopConnectionAttempts()

    Events

    Connected

    Called when a TCP connection is made. Not called for UDP Socketers. Will typically NOT be on the same thread as your UI/Update thread.

    Declaration
    public event Action<SocketerClient, int, string> Connected
    Event Type
    Type Description
    Action<SocketerClient, Int32, String>

    Disconnected

    Called when a TCP connection is lost. Not called for UDP Socketers. Will typically NOT be on the same thread as your UI/Update thread.

    Declaration
    public event Action<SocketerClient, int, string> Disconnected
    Event Type
    Type Description
    Action<SocketerClient, Int32, String>

    Message

    Called when a message is received. Will typically NOT be on the same thread as your UI/Update thread. This is by design. The Unity MonoBehaviour does call this on the Update thread; see that class for a suggested implementation of handling threads. If a Dispatcher is available, simply call that in your handler for this event.

    Declaration
    public event Action<SocketerClient, MessageEvent> Message
    Event Type
    Type Description
    Action<SocketerClient, MessageEvent>
    In This Article
    • Constructors
      • SocketerClient(SocketerClient.Protocol, Int32)
      • SocketerClient(SocketerClient.Protocol, String, Int32)
    • Properties
      • Host
      • OutputQueueLength
      • Port
      • SocketDirection
      • SocketProtocol
      • SuppressUDPHeaders
    • Methods
      • CreateListener(SocketerClient.Protocol, Int32)
      • CreateSender(SocketerClient.Protocol, String, Int32)
      • Disconnect(Int32)
      • GetLocalIPAddress()
      • SendNetworkMessage(Byte[], Int32)
      • SendNetworkMessage(String, Int32)
      • Start()
      • Stop()
      • StopConnectionAttempts()
    • Events
      • Connected
      • Disconnected
      • Message
    Back to top Generated by DocFX