/// <summary> /// initialize pomelo client /// </summary> /// <param name="host">server name or server ip (www.xxx.com/127.0.0.1/::1/localhost etc.)</param> /// <param name="port">server port</param> /// <param name="callback">socket successfully connected callback(in network thread)</param> public void initClient(string host, int port, Action callback = null) { eventManager = new EventManager(); TransporterBase transporter = null; switch (this.transporterType) { case TransportType.TCP: transporter = new TransporterTCP(); break; case TransportType.SSL: transporter = new TransporterSSL(); break; } transporter.NetWorkStateChangedEvent += NetWorkChanged; transporter.Init(host, port, (isInit) => { if (isInit) { this.protocol = new Protocol(this, transporter); if (callback != null) { callback(); } } else { Dispose(); } }); }
public Protocol(PomeloClient pc, TransporterBase inTransporter) { this.pc = pc; this.transporter = inTransporter; this.transporter.SetMessageProcesser(this.processMessage); this.transporter.onDisconnect = onDisconnect; this.handshake = new HandShakeService(this); this.state = ProtocolState.start; }