Skip to content

Server events

Mathias Cloet edited this page Feb 6, 2020 · 1 revision

A list of all events that can be triggered on the server side. At the end is an example.

/// <summary>
/// Only thrown when using ssl
/// </summary>
public event AuthenticationFailure AuthFailure;

/// <summary>
/// Only thrown when using ssl
/// </summary>
public event AuthenticationSuccess AuthSuccess;

/// <summary>
/// Event that is triggered when the server receives a Message.
/// </summary>
public event MessageReceivedDelegate MessageReceived;

/// <summary>
/// Event that is triggered when the server receives a Message with a custom header.
/// </summary>
public event MessageWithMetadataReceivedDelegate MessageWithMetaDataReceived;

/// <summary>
/// Event that is triggered when the server receives bytes from a client.
/// </summary>
public event BytesReceivedDelegate BytesReceived;

/// <summary>
/// Event that is triggered when the server receives an object from a client
/// </summary>
public event ObjectReceivedDelegate ObjectReceived;

/// <summary>
/// Event that is triggered when the server receives an update on a filetransfer.
/// This is invoked when sending a File/Folder.
/// </summary>
public event MessageUpdateFileTransferDelegate MessageUpdateFileTransfer;

/// <summary>
/// Event that is triggered when sending a message, giving an update of the state.
/// </summary>
public event MessageUpdateDelegate MessageUpdate;

/// <summary>
/// Gives progress of current filetransfer.
/// </summary>
public event FileReceiverDelegate FileReceiver;

/// <summary>
/// Gives progress of current filetransfer.
/// </summary>
public event FolderReceiverDelegate FolderReceiver;

/// <summary>
/// Event that is triggered when the server successfully has submitted a transmission of data.
/// The bool represents if the server has terminated after the message.
/// </summary>
public event MessageSubmittedDelegate MessageSubmitted;

/// <summary>
/// Event that is triggered when a client disconnects from the server.
/// </summary>
public event ClientDisconnectedDelegate ClientDisconnected;

/// <summary>
/// Event that is triggered when a client connects to the server
/// </summary>
public event ClientConnectedDelegate ClientConnected;

/// <summary>
/// Event that triggers when the server has successfully started
/// </summary>
public event ServerHasStartedDelegate ServerHasStarted;

/// <summary>
/// Event that is triggered when the server has failed to sent a sequence of bytes.
/// </summary>
public event MessageFailedDelegate MessageFailed;

/// <summary>
/// Event that is triggered when exceptions are thrown within the server
/// </summary>
public event ServerErrorThrownDelegate ServerErrorThrown;

/// <summary>
/// Event that Logs messages
/// </summary>
public event ServerLogsDelegate ServerLogs;
public delegate void MessageReceivedDelegate(IClientInfo client, string message);

public delegate void MessageWithMetadataReceivedDelegate(IClientInfo client, object message, IDictionary<object,object> metadata, Type objType);

public delegate void BytesReceivedDelegate(IClientInfo client, byte[] messageData);

public delegate void ObjectReceivedDelegate(IClientInfo client, object obj, Type type);

public delegate void MessageUpdateFileTransferDelegate(IClientInfo client, string origin, string remoteLoc,double percentageDone, MessageState state);

public delegate void MessageUpdateDelegate(IClientInfo client, string origin, string remoteLoc, MessageType messageType,MessageState messageState);

public delegate void FileReceiverDelegate(IClientInfo client, int currentPart, int totalPart, string output,MessageState messageState);

public delegate void FolderReceiverDelegate(IClientInfo client, int currentPart, int totalPart, string output,MessageState messageState);

public delegate void MessageSubmittedDelegate(IClientInfo client, bool close);

public delegate void ClientDisconnectedDelegate(IClientInfo client, DisconnectReason reason);

public delegate void ClientConnectedDelegate(IClientInfo clientInfo);

public delegate void ServerHasStartedDelegate();

public delegate void MessageFailedDelegate(IClientInfo client, byte[] messageData, Exception ex);

public delegate void ServerErrorThrownDelegate(Exception ex);

public delegate void ServerLogsDelegate(string log);

public delegate void AuthenticationSuccess(IClientInfo client);

public delegate void AuthenticationFailure(IClientInfo client);
private SimpleSocketListener _listener;
private static void Start() {
        _listener = new SimpleSocketTcpListener();
        BindEvents();
        _listener.StartListening(13000);
}

private static void BindEvents()
{
	//Events
	_listener.AuthFailure += ListenerOnAuthFailure;
	_listener.AuthSuccess += ListenerOnAuthSuccess;
	_listener.FileReceiver += ListenerOnFileReceiver;
	_listener.FolderReceiver += ListenerOnFolderReceiver;
	_listener.MessageReceived += MessageReceived;
	_listener.MessageSubmitted += MessageSubmitted;
	_listener.MessageWithMetaDataReceived += MessageWithMetaData;
	_listener.ClientDisconnected += ClientDisconnected;
	_listener.ClientConnected += ClientConnected;
	_listener.ServerHasStarted += ServerHasStarted;
	_listener.MessageFailed += MessageFailed;
	_listener.ServerErrorThrown += ErrorThrown;
	_listener.ObjectReceived += ListenerOnObjectReceived;
	_listener.MessageUpdateFileTransfer += ListenerOnMessageUpdateFileTransfer;
	_listener.MessageUpdate += ListenerOnMessageUpdate;
	_listener.ServerLogs += listener_ServerLogs;

}

private static void listener_ServerLogs(string log)
{
}

private static void ListenerOnAuthFailure(IClientInfo client)
{
}

private static void ListenerOnAuthSuccess(IClientInfo client)
{
}

private static void ListenerOnMessageUpdate(IClientInfo client, string msg, string header, MessageType msgType, MessageState state)
{
}

private static void ListenerOnMessageUpdateFileTransfer(IClientInfo client, string origin, string loc, double percentageDone, MessageState state)
{
}

private static void ListenerOnObjectReceived(IClientInfo client, object obj, Type objType)
{
}

private static void ListenerOnFolderReceiver(IClientInfo client, int currentPart, int totalParts, string loc, MessageState state)
{
}

private static void ListenerOnFileReceiver(IClientInfo client, int currentPart, int totalParts, string loc, MessageState state)
{
}

private static void MessageWithMetaData(IClientInfo client, object msg, IDictionary<object, object> metadata, Type objectType)
{
}

private static void MessageReceived(IClientInfo client, string msg)
{
}

private static void MessageSubmitted(IClientInfo client, bool close)
{
}

private static void ServerHasStarted()
{
}

private static void ErrorThrown(Exception exception)
{
}

private static void MessageFailed(IClientInfo client, byte[] messageData, Exception exception)
{
}

private static void ClientConnected(IClientInfo client)
{
}

private static void ClientDisconnected(IClientInfo client, DisconnectReason reason)
{
}
Clone this wiki locally