public void StartServerConnection()
{
if (IsConnectedToClients)
{
throw new InvalidOperationException("Cannot set up a server connection when already listening on clients.");
}
IsConnectedToServer = true;
Connector conn = new Connector(Port);
connections.Add(conn.ID, conn);
TcpClient client = new TcpClient();
Subscribe(conn);
try
{
client.Connect(Host, Port);
conn.Start(client);
OnEvent(NewConnectionCreated, new ConnectionEventArgs(conn.ID));
}
catch (SocketException)
{
if (UnableToConnect != null)
{
UnableToConnect(this, EventArgs.Empty);
}
}
catch (Exception)
{
if (CrashOnException)
{
throw;
}
}
}
public event EventHandler UnableToConnect;