void _esp_SocketOpened(object sender, int channel, out bool fHandled)
        {
            // This could be the result of an outgoing or incoming socket connection

            if (_onServerConnectionOpenedHandler == null || _sockets[channel] != null)
            {
                fHandled = false;
                return;
            }

            // Create a socket object - TODO: get tcp and port information
            var socket = new WifiSocket(this, channel, _inboundPort);

            _sockets[channel] = socket;

            // Fire connection-received event so that the app knows there is a new socket to service
            if (_onServerConnectionOpenedHandler != null)
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    _onServerConnectionOpenedHandler(this, ((WifiSocket)state));
                }, socket);
            }

            fHandled = false;
        }
        public ISocket OpenSocket(string hostNameOrAddress, int portNumber, bool useTcp)
        {
            EnsureInitialized();
            lock (_oplock)
            {
                int iSocket = -1;
                // lastSocketUsed is used to make sure that we don't reuse a just-released socket too quickly
                // It can still happen, but this reduces the probability of it happening if you are using less than five sockets in quick succession.
                // The chip seems to get upset if we reuse a socket immediately after closing it.
                for (int i = _lastSocketUsed; i < _sockets.Length; ++i)
                {
                    if (_sockets[i] == null)
                    {
                        iSocket = i;
                        break;
                    }
                }
                if (iSocket < 0)
                {
                    throw new Exception("Too many sockets open - you must close one first.");
                }

                var result = new WifiSocket(this, iSocket, hostNameOrAddress, portNumber, useTcp);
                _sockets[iSocket] = result;
                _lastSocketUsed   = iSocket;

                return(OpenSocket(iSocket));
            }
        }
示例#3
0
        public ISocket OpenSocket(string hostNameOrAddress, int portNumber, bool useTcp)
        {
            EnsureInitialized();
            lock (_oplock)
            {
                int iSocket = -1;
                // lastSocketUsed is used to make sure that we don't reuse a just-released socket too quickly
                // It can still happen, but this reduces the probability of it happening if you are using less than five sockets in quick succession.
                // The chip seems to get upset if we reuse a socket immediately after closing it.
                for (int i = _lastSocketUsed ; i < _sockets.Length; ++i)
                {
                    if (_sockets[i] == null)
                    {
                        iSocket = i;
                        break;
                    }
                }
                if (iSocket < 0)
                {
                    throw new Exception("Too many sockets open - you must close one first.");
                }

                var result = new WifiSocket(this, iSocket, hostNameOrAddress, portNumber, useTcp);
                _sockets[iSocket] = result;
                _lastSocketUsed = iSocket;

                return OpenSocket(iSocket);
            }
        }
示例#4
0
        void _esp_SocketOpened(object sender, int channel, out bool fHandled)
        {
            // This could be the result of an outgoing or incoming socket connection

            if (_onServerConnectionOpenedHandler==null || _sockets[channel]!=null)
            {
                fHandled = false;
                return;
            }

            // Create a socket object - TODO: get tcp and port information
            var socket = new WifiSocket(this, channel, _inboundPort);
            _sockets[channel] = socket;

            // Fire connection-received event so that the app knows there is a new socket to service
            if (_onServerConnectionOpenedHandler != null)
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    _onServerConnectionOpenedHandler(this, ((WifiSocket)state));
                }, socket);
            }

            fHandled = false;
        }
示例#5
0
 private static void OnServerConnectionOpened(object sender, WifiSocket socket)
 {
     socket.DataReceived += socket_DataReceived;
     socket.SocketClosed += socket_SocketClosed;
 }