bool CreateConnection(Socket connection) { var conn = new ReceiverConnection(connection, new[] { PublicConnectionPassword }); bool accepted = false; try { accepted = conn.DoInitialHandshake(); } catch (InvalidHandshakeException ex) { RaiseFailedConnectionAttempt(ex); } if (accepted) RaiseGotConnection(conn); else conn.Dispose(); return accepted; }
void RaiseGotConnection(ReceiverConnection conn) { UIThreadSyncContext.Send(new SendOrPostCallback(state => { if (GotConnection != null) GotConnection(conn); }), null); }