//================== public void Reset() { Stop(); rwlock_object.EnterWriteLock(); try { if (STATE != SERVERSTATE.FREE) { listener_object = null; send_buffer.Clear(); receive_buffer.Clear(); STATE = SERVERSTATE.FREE; logger.Print(LOGLEVEL.INFO, "Broadcast server reset."); } } finally { rwlock_object.ExitWriteLock(); } }
//================== public BroadcastServer(LOGGER logObj) { logger = logObj; rwlock_object = new ReaderWriterLockSlim(); listener_object = null; //准备客户端 int count = (int)GLOBAL.NETSOCK_MAX_CLIENT_COUNT; client_object = new TCPObject[count]; for (int i = 0; i < count; i++) { client_object[i] = new TCPObject(logObj); } //buffer send_buffer = new StringBuffer(); receive_buffer = new StringBuffer(); STATE = SERVERSTATE.FREE; }
public bool Init(int port) { Reset(); bool state = true; rwlock_object.EnterWriteLock(); try { listener_object = new TCPListener(logger); listener_object.Bind(port); if (listener_object.STATE == TCPSTATE.INSTALL) { STATE = SERVERSTATE.INSTALL; logger.Print(LOGLEVEL.INFO, "Broadcast server init succesfully."); } else { state = false; } } finally { rwlock_object.ExitWriteLock(); } return(state); }