-
Notifications
You must be signed in to change notification settings - Fork 31
Server
Mathias Cloet edited this page Feb 6, 2020
·
1 revision
Creating the Server
//Create Regular server
SimpleSocketListener listener = new SimpleSocketTcpListener();
//Create Ssl server
//(Certificate will be a .pfx) file
SimpleSocketListener listener = new SimpleSocketTcpSslListener("path to certificate","password");
Starts the server
//Starts the server
string ip = "127.0.0.1"
int port = 13000;
listener.StartListening(ip,port);
Events
The server has various events that have to be bound.
Below is an example of how I bind my events.
```C#
//Events
_listener.AuthFailure += ListenerOnAuthFailure;
_listener.AuthSuccess += ListenerOnAuthSuccess;
_listener.FileReceiver += ListenerOnFileReceiver;
_listener.FolderReceiver += ListenerOnFolderReceiver;
_listener.MessageReceived += MessageReceived;
_listener.MessageSubmitted += MessageSubmitted;
_listener.CustomHeaderReceived += CustomHeaderReceived;
_listener.ClientDisconnected += ClientDisconnected;
_listener.ClientConnected += ClientConnected;
_listener.ServerHasStarted += ServerHasStarted;
_listener.MessageFailed += MessageFailed;
_listener.ServerErrorThrown += ErrorThrown;
_listener.ObjectReceived += ListenerOnObjectReceived;
_listener.MessageUpdateFileTransfer += ListenerOnMessageUpdateFileTransfer;
_listener.MessageUpdate += ListenerOnMessageUpdate;
Methods used to send messages to clients
//Send
public void SendMessage(int id,string message, bool compress = false, bool encrypt = false, bool close = false);
public async Task SendMessageAsync(int id,string message, bool compress = false, bool encrypt = false, bool close = false);
public void SendBytes(int id,byte[] data, bool compress = false, bool encrypt = false, bool close = false);
public async Task SendBytesAsync(int id,byte[] data, bool compress = false, bool encrypt = false, bool close = false);
public void SendMessageContract(int id,IMessageContract contract, bool compress = false, bool encrypt = false,bool close = false);
public async Task SendMessageContractAsync(int id,IMessageContract contract, bool compress = false, bool encrypt = false, bool close = false);
public void SendCustomHeader(int id,string message, string header, bool compress = false, bool encrypt = false, bool close = false);
public void SendCustomHeader(int id,byte[] data, byte[] header, bool compress = false, bool encrypt = false, bool close = false);
public async Task SendCustomHeaderAsync(int id,string message, string header, bool compress = false, bool encrypt = false, bool close = false);
public async Task SendCustomHeaderAsync(int id,byte[] data, byte[] header, bool compress = false, bool encrypt = false, bool close = false);
public async Task SendFileAsync(int id,string fileLocation, string remoteSaveLocation, bool compress = true, bool encrypt = false, bool close = false);
public void SendFile(int id,string fileLocation, string remoteSaveLocation, bool compress = true, bool encrypt = false, bool close = false);
public async Task SendFolderAsync(int id,string folderLocation, string remoteSaveLocation,bool encrypt = false, bool close = false);
public void SendFolder(int id,string folderLocation, string remoteSaveLocation,bool encrypt = false, bool close = false);
public async Task SendObjectAsync(int id,object obj, bool compress = false, bool encrypt = false, bool close = false);
public void SendObject(int id,object obj, bool compress = false, bool encrypt = false, bool close = false);