Skip to main content
Version: 2.x

Class Socket

An ODIN socket, which handles the underlying native opaque socket handle. This abstraction provides a high-level interface for sending and receiving messages to and from a peer.

Declaration
public class Socket : ISocket, IDisposable

Implements:
OdinNative.Wrapper.ISocket, System.IDisposable

Properties

Id

Socket id

Declaration
public ulong Id { get; }

Info

Declaration
public NativeBindings.OdinSocketInfo Info { get; }

Label

Socket label

Declaration
public int Label { get; }

IsRemote

Socket ownership check

Declaration
public bool IsRemote { get; }

IsClosed

IsClosed

Declaration
public bool IsClosed { get; }

Parent

Default value null indicates root or not set

Declaration
public IPeer Parent { get; set; }

Room

Declaration
public IRoom Room { get; set; }

Methods

OnSocket(IRoom, SocketMessageEventArgs)

Forward on socket data

Declaration
public virtual void OnSocket(IRoom room, SocketMessageEventArgs args)
Parameters
TypeName
OdinNative.Wrapper.IRoomroom
OdinNative.Wrapper.Socket.SocketMessageEventArgsargs

Create(IRoom, OdinSocketKind, uint, int, int)

Initialise and opens a socket

Declaration
public static Socket Create(IRoom room, NativeBindings.OdinSocketKind kind, uint targetPeerId, int label, int priority)
Returns

OdinNative.Wrapper.Socket.Socket: Socket object

Parameters
TypeNameDescription
OdinNative.Wrapper.IRoomroomRoom to open the socket in
OdinNative.Core.Imports.NativeBindings.OdinSocketKindkindType of socket to open
System.UInt32targetPeerIdremote peer id
System.Int32labelsocket name
System.Int32prioritysocket priority

GetBaseSocket<T>()

This will always return itself

Declaration
public T GetBaseSocket<T>() where T : ISocket
Returns

<T>

Type Parameters
  • T

RefreshHandle(int)

Refresh the native socket handle and pull socket info

Declaration
public bool RefreshHandle(int peerId = -1)
Returns

System.Boolean: true on new handle

Parameters
TypeNameDescription
System.Int32peerIddefault (-1) uses the last remote peer id

Socket_OnMessageReceived(object, IRoom, byte[])

Declaration
public virtual void Socket_OnMessageReceived(object sender, IRoom room, byte[] message)
Parameters
TypeName
System.Objectsender
OdinNative.Wrapper.IRoomroom
System.Byte[]message

Open(OdinSocketKind, uint, int, int)

Declaration
public bool Open(NativeBindings.OdinSocketKind kind, uint targetPeerId, int label, int priority)
Returns

System.Boolean

Parameters
TypeName
OdinNative.Core.Imports.NativeBindings.OdinSocketKindkind
System.UInt32targetPeerId
System.Int32label
System.Int32priority

GetSocketId()

Retrieves the socket id

Declaration
public ulong GetSocketId()
Returns

System.UInt64: socket id

GetSocketInfo()

Declaration
public NativeBindings.OdinSocketInfo GetSocketInfo()
Returns

OdinNative.Core.Imports.NativeBindings.OdinSocketInfo

Send(string)

Sends an utf8 string message to the peer

Declaration
public NativeBindings.OdinError Send(string message)
Returns

OdinNative.Core.Imports.NativeBindings.OdinError: OdinError

Parameters
TypeNameDescription
System.Stringmessagetext message

Send(byte[])

Sends an arbitrary message to the peer

Declaration
public NativeBindings.OdinError Send(byte[] message)
Returns

OdinNative.Core.Imports.NativeBindings.OdinError: OdinError

Parameters
TypeNameDescription
System.Byte[]messagearbitrary message

Reset()

Close the native socket. (native dispose) Therefore local socket can not send.

Declaration
public void Reset()

Dispose(bool)

On dispose will close the socket

Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeName
System.Booleandisposing

~Socket()

Finalizer

Declaration
protected ~Socket()

Dispose()

On dispose will free the socket and all associated data

Declaration
public void Dispose()

Events

OnMessageReceived

Odin socket received message

Declaration
public event OnSocketMessageReceivedDelegate OnMessageReceived
Event Type

OdinNative.Wrapper.OnSocketMessageReceivedDelegate

Implements