c# - Properties and onchange events. Need to find a proper design pattern -
so made socket communication library. , part of iconnection
public enum connectionstate { notconnected, connecting, connected, authenticated, disconnecting, disconnected } public interface iconnection { connectionstate state { get; } event action connected; event action disconnected; event action authenticated; event action authenticationfailed; // 2 methods core of question void onauthenticated(); void onauthenticationfailed(); bool send(byte[] data); void connect(); void close(); }
of course of study iconnection
provides info connection state , able fire connected/disconnected
events holds socket
. there no doubt.
now, users of iconnection
know when becomes authenticated. example, server might hear events, , 1 time connection authenticated - send client's initial configuration data. or client might hear events , decide start communication or retry authentication process.
but. problem is, authentication process exists in protocol layer. iconnection
has no thought such layer exists. protocol layer uses iconnection
send serialized byte[]
message other party.
so, iconnection
able alter it's state , inform subscribers on auth process had implement 2 methods
void onauthenticated(); void onauthenticationfailed();
which are, called protocol layer authentication process code.
i sense i'm doing wrong here. , since work alone, thoughts much appreciated.
i ended moving core part of protocol authentication, keep-alive service , basic message types used everywhere communication assembly.
so iconnection
auth process aware of core protocol.
c# architecture
No comments:
Post a Comment