public void connect(ConnectionCallback onComplete)
        {
            CallbackState state = new CallbackState(socket, onComplete);

            try
            {
                socket.BeginConnect(ipEndPoint, ConnectCallback, state);
            }
            //catch (ArgumentNullException ae)
            //{
            //    Console.WriteLine("ArgumentNullException : {0}", ae.ToString());
            //}
            //catch (SocketException se)
            //{
            //    Console.WriteLine("SocketException : {0}", se.ToString());
            //}
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
                var connectionResult = new ConnectionResult();
                connectionResult.result  = ConnectionResult.Result.FAILURE;
                connectionResult.Message = e.Message;
                onComplete.Invoke(connectionResult);
            }
        }
Ejemplo n.º 2
0
        public WebSocketIO Connect(ConnectionCallback onSuccess, ConnectionCallbackError onError)
        {
            m_webSocket.OnOpen    += EventHandlerOnOpen;
            m_webSocket.OnClose   += EventHandlerOnClose;
            m_webSocket.OnMessage += EventHandlerOnMessage;
            m_webSocket.OnError   += EventHandlerOnError;

            m_webSocket.OnOpen  += OnOpen;
            m_webSocket.OnClose += OnClose;
            m_webSocket.Connect();
            return(this);

            void OnOpen(object sender, EventArgs e)
            {
                m_webSocket.OnOpen  -= OnOpen;
                m_webSocket.OnClose -= OnClose;
                onSuccess?.Invoke();
            }

            void OnClose(object sender, CloseEventArgs e)
            {
                m_webSocket.OnOpen  -= OnOpen;
                m_webSocket.OnClose -= OnClose;
                onError?.Invoke(e.Code, e.Reason, e.WasClean);
            }
        }
Ejemplo n.º 3
0
 public Server(IO.Context context, ConnectionCallback callback, ITcpServerSocket socket, bool closeOnEnd = false)
 {
     this.callback = callback;
     this.socket = socket;
     this.closeOnEnd = closeOnEnd;
     this.Context = context;
 }
Ejemplo n.º 4
0
 protected void UpdateConnectionStatus(int step, CableInfo info, ConnectionCallback callback)
 {
     if (callback != null)
     {
         callback(step, info);
         System.Threading.Thread.Sleep(100);
     }
 }
Ejemplo n.º 5
0
 public void setConnectionCallback(ISplitSensorConnectionCallback callback)
 {
             #if UNITY_ANDROID
     if (nativeController != null)
     {
         var ConnectionCallback = new ConnectionCallback();
         nativeController.Call("setConnectionCallback", ConnectionCallback);
     }
             #endif
     mSplitSensorConnectionCallback = callback;
 }
Ejemplo n.º 6
0
        public Transaction(Server server, ITcpSocket socket, ConnectionCallback callback, bool closeOnEnd = false)
        {
            Server = server;
            Socket = socket;
            this.closeOnEnd = closeOnEnd;

            Context = server.Context;

            ConnectionCallback = callback;

            gc_handle = GCHandle.Alloc(this);

            Request = new Request(this, socket);
            Request.Read(Close);
        }
        public DroidReachabilityService(IMvxMessenger messenger)
        {
            _messenger = messenger;
            _manager   = (ConnectivityManager)Application.Context.GetSystemService(Context.ConnectivityService);

            if (Build.VERSION.SdkInt <= BuildVersionCodes.N)
            {
                var receiver = new ConnectionBroadcastReceiver(this);
#pragma warning disable CS0618 // Type or member is obsolete
                Application.Context.RegisterReceiver(receiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
#pragma warning restore CS0618 // Type or member is obsolete
            }
            else
            {
                var callback = new ConnectionCallback(this);
                _manager.RegisterDefaultNetworkCallback(callback);
            }
        }
Ejemplo n.º 8
0
        public int Init(Action <byte, DolphiimoteData> newData, Action <byte, bool> wiimoteConnectionChanged, Action <byte, DolphiimoteCapabilities> capabilitiesChanged, Action <string> newLogMessage)
        {
            dataCallback         = (wiimote, data, user) => newData(wiimote, MarshalType <DolphiimoteData>(data));
            capabilitiesCallback = (wiimote, capabilities, user) => capabilitiesChanged(wiimote, MarshalType <DolphiimoteCapabilities>(capabilities));
            connectionCallback   = (wiimote, status) => wiimoteConnectionChanged(wiimote, Convert.ToBoolean(status));
            logCallback          = (str, length) => newLogMessage(Marshal.PtrToStringAnsi(str, (int)length));

            var callbacks = new DolphiimoteCallbacks
            {
                dataReceived        = MarshalFunction(dataCallback),
                capabilitiesChanged = MarshalFunction(capabilitiesCallback),
                connectionChanged   = MarshalFunction(connectionCallback),
                onLog    = MarshalFunction(logCallback),
                userData = IntPtr.Zero
            };

            return(dolphiimoteInit(callbacks));
        }
Ejemplo n.º 9
0
        public async Task OpenAsync(ConnectionCallback callback = null)
        {
            try
            {
                await socket.ConnectTaskAsync(RemoteEndPoint).ConfigureAwait(false);

                IsConnected = true;
            }
            catch (SocketException ex)
            {
                IsConnected = false;
                throw new CommunicationException("Подключение не установлено.", ex);
            }

            if (callback != null)
            {
                await callback.Invoke().ConfigureAwait(false);
            }
        }
Ejemplo n.º 10
0
        public static Transaction BeginTransaction(Server server, ITcpSocket socket, ConnectionCallback cb, bool closeOnEnd = false)
        {
            Transaction transaction = new Transaction(server, socket, cb, closeOnEnd);

            return transaction;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initialize a new object of LiteServer
 /// </summary>
 /// <param name="port">The port to listen at</param>
 public LiteServer(ushort port)
     : base(new ServersProps(port))
 {
     Clients = new List <Client>();
     this._clientDisconnected = ClientDisconnected;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Recieve multiple connections, each connection is passed to the callback in a new thread. Does not return.
 /// </summary>
 /// <param name="callback"></param>
 private void AcceptMultiple(ConnectionCallback callback)
 {
     while(true)
     {
         var comm = new TcpServerCommunicator(Port, AcceptClient());
         var thread = new Thread(() => callback(comm));
         thread.Start();
     }
 }
Ejemplo n.º 13
0
 public static extern int SetDefaultCellularServiceProfileAsync(IntPtr handle, int Type, IntPtr profileHandle, ConnectionCallback callback, IntPtr userData);
Ejemplo n.º 14
0
 public void setCallback(ConnectionCallback callback)
 {
     lock(this)
     {
         if(_state >= StateClosed)
         {
             if(callback != null)
             {
                 _threadPool.dispatch(() =>
                 {
                     try
                     {
                         callback.closed(this);
                     }
                     catch(System.Exception ex)
                     {
                         _logger.error("connection callback exception:\n" + ex + '\n' + _desc);
                     }
                 } , this);
             }
         }
         else
         {
             _callback = callback;
         }
     }
 }
 public ConnectionListener(ShowResultCallback showResult, ConnectionCallback onConnectDoneCallback)
 {
     mShowResultCallback    = showResult;
     mOnConnectDoneCallback = onConnectDoneCallback;
 }
 public void AddConnectionRecoverableCallbacks(ConnectionCallback mRecoverable, ConnectionCallback mRecovered)
 {
     mConnectionRecoverableError = mRecoverable;
     mConnectionRecoverd         = mRecovered;
 }
Ejemplo n.º 17
0
 public void Listen(int backlog, ConnectionCallback connectionCallback)
 {
     _connectionCallback = connectionCallback;
     LibuvNative.uv_listen(this, backlog, ConnectionCb);
 }
Ejemplo n.º 18
0
 public static extern int CloseProfile(IntPtr handle, IntPtr profileHandle, ConnectionCallback callback, IntPtr userData);
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new instance of CustomCable.
        /// </summary>
        /// <param name="port"> The port the cable is connected to. </param>
        /// <param name="timeoutMilliseconds"> The timeout to use for communication with the cable. </param>
        public Elm327Cable(string port, int timeoutMilliseconds, ConnectionCallback callback) :
            base(port, timeoutMilliseconds, 38400)
        {
            CableType     = Type.Elm327;
            IsInitialized = false; // default to false

            // default cable info
            CableInfo info = new CableInfo();

            // set the newline character to be what elm327 uses
            cableConnection.NewLine = Protocols.Elm327.EndOfLine;

            info.Description = "Discovering ELM version";
            UpdateConnectionStatus(1, info, callback);

            // detect what type of cable is connected
            string response = SendCommand(Protocols.Elm327.Reset, 1000);

            if (response.Contains(Protocols.Elm327.Header))
            {
                Diagnostics.DiagnosticLogger.Log("Cable is ELM327 type");

                string version = "NA";

                // get the version number for posterity
                if (response.Contains("v"))
                {
                    int indexOfVersion = response.IndexOf("v");
                    version = response.Substring(indexOfVersion);
                    Diagnostics.DiagnosticLogger.Log("Discovered ELM version: " + version);

                    info.Description = "Discovered ELM version: " + version;
                    info.Version     = version;
                    UpdateConnectionStatus(1, info, callback);
                }

                // turn echo off
                Diagnostics.DiagnosticLogger.Log("Turning echo off");
                info.Description = "Turning echo off";
                UpdateConnectionStatus(1, info, callback);

                response = SendCommand(Protocols.Elm327.EchoOff, 10000);
                if (!response.Contains(Protocols.Elm327.Responses.OK))
                {
                    Diagnostics.DiagnosticLogger.Log("Could not turn echo off");
                    return;
                }

                info.EchoOff     = true;
                info.Description = "Turning auto protocol on";
                UpdateConnectionStatus(2, info, callback);

                Diagnostics.DiagnosticLogger.Log("Turning auto protocol on");
                response = SendCommand(Protocols.Elm327.SetAutoProtocol, 10000);
                if (!response.Contains(Protocols.Elm327.Responses.OK))
                {
                    Diagnostics.DiagnosticLogger.Log("Could not set protocol to Auto");
                    return;
                }

                info.Description = "Forcing search for vehicle's protocol";
                UpdateConnectionStatus(2, info, callback);

                Diagnostics.DiagnosticLogger.Log("Forcing a search for existing protocol");
                response = SendCommand(Protocols.Elm327.ForceProtocolSearch, 10000);
                if (string.IsNullOrEmpty(response))
                {
                    Diagnostics.DiagnosticLogger.Log("Could not force an auto protocol search");
                    info.Description = "Error, could not force an auto protocol search";
                    UpdateConnectionStatus(2, info, callback);
                    return;
                }

                response = SendCommand(Protocols.Elm327.DisplayProtocol, 10000);
                string chosenProtocol = response.Replace(Protocols.Elm327.Responses.Auto, string.Empty).Replace(",", string.Empty).Trim();
                Diagnostics.DiagnosticLogger.Log("Protocol chosen: " + chosenProtocol);
                if (!response.Contains(Protocols.Elm327.Responses.Auto))
                {
                    Diagnostics.DiagnosticLogger.Log("Displayed protocol did not mention auto");
                    info.Description = "Error, displayed protocol did not mention auto";
                    UpdateConnectionStatus(2, info, callback);
                    //return;
                }

                Protocol             = OBD2.Protocols.NameToProtocol(chosenProtocol);
                info.Protocol        = Protocol;
                info.AutoProtocolSet = true;
                info.Description     = "Protocol has been chosen";
                UpdateConnectionStatus(3, info, callback);

                // everything is good to go
                IsInitialized = true;

                // fully initialized, the fourth step is the final step
                info.Description = "Connected!";
                UpdateConnectionStatus(4, info, callback);
            }
        }
Ejemplo n.º 20
0
 public static extern int ResetProfile(IntPtr handle, int Option, int Id, ConnectionCallback callback, IntPtr userData);
 public CallbackState(Socket socket, ConnectionCallback callback)
 {
     this.socket   = socket;
     this.callback = callback;
 }
 public ConnectionListener(ShowResultCallback showResult, ConnectionCallback onConnectDoneCallback)
 {
     mShowResultCallback = showResult;
     mOnConnectDoneCallback = onConnectDoneCallback;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Recieve multiple connections, each connection is passed to the callback in a new thread. Does not return.
 /// </summary>
 /// <param name="callback"></param>
 public void Initialize(ConnectionCallback callback)
 {
     _thread = new Thread(() => AcceptMultiple(callback));
 }
 public void AddConnectionRecoverableCallbacks(ConnectionCallback mRecoverable, ConnectionCallback mRecovered)
 {
     mConnectionRecoverableError = mRecoverable;
     mConnectionRecoverd = mRecovered;
 }
 public static extern MLResult.Code MLAppConnectRegisterConnectionCallback(ref ConnectionCallback connection_callback, ref ulong outCallbackHandle);