ProtonNet Server 1.0
An Open Solution for all your socket or web api needs.
Loading...
Searching...
No Matches
XmobiTea.ProtonNetServer.UdpServer Class Reference

Represents a UDP server that provides functionalities for managing UDP connections and data transmission. More...

Inheritance diagram for XmobiTea.ProtonNetServer.UdpServer:
XmobiTea.ProtonNetServer.IUdpServer XmobiTea.ProtonNetServer.IServer XmobiTea.ProtonNet.Server.Socket.Server.SocketUdpServer

Public Member Functions

 UdpServer (string address, int port, UdpServerOptions options)
 Initializes a new instance of the UdpServer class with the specified address, port, and options.
 
virtual bool Start (string multicastAddress, int multicastPort)
 Starts the UDP server with the specified multicast address and port.
 
virtual bool Start ()
 Starts the UDP server.
 
virtual bool Stop ()
 Stops the UDP server.
 
virtual bool Restart ()
 Restarts the UDP server.
 
virtual bool BroadcastAll (byte[] buffer)
 Broadcasts a message to all clients using the specified buffer.
 
virtual bool BroadcastAll (byte[] buffer, int position, int length)
 Broadcasts a message to all clients using the specified buffer, position, and length.
 
virtual bool BroadcastAllAsync (byte[] buffer)
 Broadcasts a message asynchronously to all clients using the specified buffer.
 
virtual bool BroadcastAllAsync (byte[] buffer, int position, int length)
 Broadcasts a message asynchronously to all clients using the specified buffer, position, and length.
 
virtual bool DisconnectAll ()
 Disconnects all connected sessions.
 
IServerNetworkStatistics GetNetworkStatistics ()
 Retrieves the server's network statistics.
 
virtual bool SendAsync (EndPoint endpoint, byte[] buffer)
 Sends a datagram asynchronously to the specified endpoint using the provided buffer.
 
virtual bool SendAsync (EndPoint endpoint, byte[] buffer, int position, int length)
 Sends a datagram asynchronously to the specified endpoint using the provided buffer, position, and length.
 
virtual int Send (EndPoint endpoint, byte[] buffer)
 Sends a datagram synchronously to the specified endpoint using the provided buffer.
 
virtual int Send (EndPoint endpoint, byte[] buffer, int position, int length)
 Sends a datagram synchronously to the specified endpoint using the provided buffer, position, and length.
 
UdpSession GetSession (string id)
 Finds a session by its unique identifier.
 
UdpSession GetSession (EndPoint endpoint)
 Finds a session by its remote endpoint.
 
void Dispose ()
 Releases the unmanaged resources used by the UdpServer and optionally releases the managed resources.
 
- Public Member Functions inherited from XmobiTea.ProtonNetServer.IUdpServer
- Public Member Functions inherited from XmobiTea.ProtonNetServer.IServer

Protected Member Functions

virtual string CreateRandomId ()
 Generates a random identifier string.
 
virtual UdpSession CreateSession ()
 Creates a new instance of the UdpSession class.
 
virtual void OnStarting ()
 Called when the server is starting.
 
virtual void OnStarted ()
 Called when the server has started.
 
virtual void OnStopping ()
 Called when the server is stopping.
 
virtual void OnStopped ()
 Called when the server has stopped.
 
virtual void OnConnecting (UdpSession session)
 Called when a session is connecting.
 
virtual void OnConnected (UdpSession session)
 Called when a session has connected.
 
virtual void OnDisconnecting (UdpSession session)
 Called when a session is disconnecting.
 
virtual void OnDisconnected (UdpSession session)
 Called when a session has disconnected.
 
virtual void OnReceived (EndPoint endpoint, byte[] buffer, int position, int length)
 Called when data is received from a remote endpoint.
 
virtual void OnSent (EndPoint endpoint, int sent)
 Called when data has been sent to a remote endpoint.
 
virtual void OnError (SocketError error)
 Called when an error occurs during a socket operation.
 
virtual void Dispose (bool disposingManagedResources)
 Releases the unmanaged resources used by the UdpServer and optionally releases the managed resources.
 

Properties

string Id [get]
 Gets the unique identifier of the server.
 
string Address [get]
 Gets the IP address of the server.
 
int Port [get]
 Gets the port number on which the server is listening.
 
EndPoint EndPoint [get]
 Gets the server's local endpoint.
 
EndPoint MulticastEndpoint [get]
 Gets the multicast endpoint used by the server.
 
ConcurrentDictionary< string, UdpSessionSessions [get]
 Gets the collection of active UDP sessions.
 
ConcurrentDictionary< System.Net.EndPoint, UdpSessionEndPointWithSocketSessionDict [get]
 Gets the dictionary that maps endpoints to UDP sessions.
 
int ConnectedSessions [get]
 Gets the number of connected sessions.
 
UdpServerOptions Options [get]
 Gets the options used by the UDP server.
 
bool IsStarted [get]
 Gets a value indicating whether the server has been started.
 
bool IsDisposed [get]
 Gets a value indicating whether the server has been disposed.
 
bool IsSocketDisposed [get]
 Gets a value indicating whether the server's socket has been disposed.
 

Detailed Description

Represents a UDP server that provides functionalities for managing UDP connections and data transmission.

Constructor & Destructor Documentation

◆ UdpServer()

XmobiTea.ProtonNetServer.UdpServer.UdpServer ( string address,
int port,
UdpServerOptions options )

Initializes a new instance of the UdpServer class with the specified address, port, and options.

Parameters
addressThe IP address of the server.
portThe port number on which the server listens.
optionsThe options used by the server.

Member Function Documentation

◆ BroadcastAll() [1/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.BroadcastAll ( byte[] buffer)
virtual

Broadcasts a message to all clients using the specified buffer.

Parameters
bufferThe data buffer to broadcast.
Returns
True if the broadcast was successful; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ BroadcastAll() [2/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.BroadcastAll ( byte[] buffer,
int position,
int length )
virtual

Broadcasts a message to all clients using the specified buffer, position, and length.

Parameters
bufferThe data buffer to broadcast.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
True if the broadcast was successful; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ BroadcastAllAsync() [1/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.BroadcastAllAsync ( byte[] buffer)
virtual

Broadcasts a message asynchronously to all clients using the specified buffer.

Parameters
bufferThe data buffer to broadcast.
Returns
True if the broadcast was successful; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ BroadcastAllAsync() [2/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.BroadcastAllAsync ( byte[] buffer,
int position,
int length )
virtual

Broadcasts a message asynchronously to all clients using the specified buffer, position, and length.

Parameters
bufferThe data buffer to broadcast.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
True if the broadcast was successful; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ CreateRandomId()

virtual string XmobiTea.ProtonNetServer.UdpServer.CreateRandomId ( )
protectedvirtual

Generates a random identifier string.

Returns
A randomly generated string.

◆ CreateSession()

virtual UdpSession XmobiTea.ProtonNetServer.UdpServer.CreateSession ( )
protectedvirtual

Creates a new instance of the UdpSession class.

Returns
A new UdpSession instance.

Reimplemented in XmobiTea.ProtonNet.Server.Socket.Server.SocketUdpServer.

◆ DisconnectAll()

virtual bool XmobiTea.ProtonNetServer.UdpServer.DisconnectAll ( )
virtual

Disconnects all connected sessions.

Returns
True if all sessions were disconnected successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ Dispose()

virtual void XmobiTea.ProtonNetServer.UdpServer.Dispose ( bool disposingManagedResources)
protectedvirtual

Releases the unmanaged resources used by the UdpServer and optionally releases the managed resources.

Parameters
disposingManagedResourcesTrue to release both managed and unmanaged resources; false to release only unmanaged resources.

◆ GetNetworkStatistics()

IServerNetworkStatistics XmobiTea.ProtonNetServer.UdpServer.GetNetworkStatistics ( )

Retrieves the server's network statistics.

Returns
An object that provides network statistics.

Implements XmobiTea.ProtonNetServer.IServer.

◆ GetSession() [1/2]

UdpSession XmobiTea.ProtonNetServer.UdpServer.GetSession ( EndPoint endpoint)

Finds a session by its remote endpoint.

Parameters
endpointThe remote endpoint.
Returns
The UdpSession associated with the specified endpoint, or null if not found.

◆ GetSession() [2/2]

UdpSession XmobiTea.ProtonNetServer.UdpServer.GetSession ( string id)

Finds a session by its unique identifier.

Parameters
idThe session identifier.
Returns
The UdpSession associated with the specified identifier, or null if not found.

◆ OnConnected()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnConnected ( UdpSession session)
protectedvirtual

Called when a session has connected.

Parameters
sessionThe session that has connected.

◆ OnConnecting()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnConnecting ( UdpSession session)
protectedvirtual

Called when a session is connecting.

Parameters
sessionThe session that is connecting.

◆ OnDisconnected()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnDisconnected ( UdpSession session)
protectedvirtual

Called when a session has disconnected.

Parameters
sessionThe session that has disconnected.

◆ OnDisconnecting()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnDisconnecting ( UdpSession session)
protectedvirtual

Called when a session is disconnecting.

Parameters
sessionThe session that is disconnecting.

◆ OnError()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnError ( SocketError error)
protectedvirtual

Called when an error occurs during a socket operation.

Parameters
errorThe socket error that occurred.

◆ OnReceived()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnReceived ( EndPoint endpoint,
byte[] buffer,
int position,
int length )
protectedvirtual

Called when data is received from a remote endpoint.

Parameters
endpointThe remote endpoint.
bufferThe data buffer containing the received data.
positionThe starting position in the buffer.
lengthThe length of the received data.

◆ OnSent()

virtual void XmobiTea.ProtonNetServer.UdpServer.OnSent ( EndPoint endpoint,
int sent )
protectedvirtual

Called when data has been sent to a remote endpoint.

Parameters
endpointThe remote endpoint.
sentThe number of bytes sent.

◆ Restart()

virtual bool XmobiTea.ProtonNetServer.UdpServer.Restart ( )
virtual

Restarts the UDP server.

Returns
True if the server restarted successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ Send() [1/2]

virtual int XmobiTea.ProtonNetServer.UdpServer.Send ( EndPoint endpoint,
byte[] buffer )
virtual

Sends a datagram synchronously to the specified endpoint using the provided buffer.

Parameters
endpointThe destination endpoint.
bufferThe data buffer to send.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IUdpServer.

◆ Send() [2/2]

virtual int XmobiTea.ProtonNetServer.UdpServer.Send ( EndPoint endpoint,
byte[] buffer,
int position,
int length )
virtual

Sends a datagram synchronously to the specified endpoint using the provided buffer, position, and length.

Parameters
endpointThe destination endpoint.
bufferThe data buffer to send.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IUdpServer.

◆ SendAsync() [1/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.SendAsync ( EndPoint endpoint,
byte[] buffer )
virtual

Sends a datagram asynchronously to the specified endpoint using the provided buffer.

Parameters
endpointThe destination endpoint.
bufferThe data buffer to send.
Returns
True if the data was successfully queued for sending; otherwise, false.

Implements XmobiTea.ProtonNetServer.IUdpServer.

◆ SendAsync() [2/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.SendAsync ( EndPoint endpoint,
byte[] buffer,
int position,
int length )
virtual

Sends a datagram asynchronously to the specified endpoint using the provided buffer, position, and length.

Parameters
endpointThe destination endpoint.
bufferThe data buffer to send.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
True if the data was successfully queued for sending; otherwise, false.

Implements XmobiTea.ProtonNetServer.IUdpServer.

◆ Start() [1/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.Start ( )
virtual

Starts the UDP server.

Returns
True if the server started successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.

◆ Start() [2/2]

virtual bool XmobiTea.ProtonNetServer.UdpServer.Start ( string multicastAddress,
int multicastPort )
virtual

Starts the UDP server with the specified multicast address and port.

Parameters
multicastAddressThe multicast address to join.
multicastPortThe multicast port to use.
Returns
True if the server started successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IUdpServer.

◆ Stop()

virtual bool XmobiTea.ProtonNetServer.UdpServer.Stop ( )
virtual

Stops the UDP server.

Returns
True if the server stopped successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IServer.


The documentation for this class was generated from the following file: