Пример #1
0
        public FPSocket(OnDataDelegate onData, string host, int port, int timeout)
        {
            this._host    = host;
            this._port    = port;
            this._timeout = timeout;
            this._onData  = onData;

            this._event = new FPEvent();
        }
Пример #2
0
        protected void Init(string host, int port, bool autoReconnect, int connectionTimeout)
        {
            this._pkg      = new FPPackage();
            this._cyr      = new FPEncryptor(_pkg);
            this._event    = new FPEvent();
            this._psr      = new FPProcessor();
            this._callback = new FPCallback();

            if (connectionTimeout > 0)
            {
                this._timeout = connectionTimeout;
            }

            this._autoReconnect = autoReconnect;

            FPClient self = this;

            this._eventDelegate = (evd) => {
                self.OnSecond(evd.GetTimestamp());
            };

            ThreadPool.Instance.Event.AddListener("second", this._eventDelegate);

            this._sock = new FPSocket((stream) => {
                self.OnData(stream);
            }, host, port, this._timeout);

            this._sock.GetEvent().AddListener("connect", (evd) => {
                self.OnConnect();
            });

            this._sock.GetEvent().AddListener("close", (evd) => {
                self.OnClose();
            });

            this._sock.GetEvent().AddListener("error", (evd) => {
                self.OnError(evd.GetException());
            });
        }