示例#1
0
        internal void ClientErrorMessageReceived(ClientErrorEventArgs args)
        {
            EventHandler <ClientErrorEventArgs> handler = ClientError;

            if (handler != null)
            {
                handler(this, args);
            }
        }
示例#2
0
 void workerBroadcast_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error == null && e.Result != null)
     {
         if (e.Result.Equals(CLIENT_ERROR_RESULT))
         {
             ClientErrorEventArgs args = new ClientErrorEventArgs()
             {
                 ErrorCode = ClientErrorEventArgs.CONNECTION_ERROR
             };
             connection.ClientErrorMessageReceived(args);
         }
     }
 }
示例#3
0
        void connection_ClientError(object sender, ClientErrorEventArgs e)
        {
            switch (e.ErrorCode)
            {
            case ClientErrorEventArgs.CONNECTION_ERROR:
                ErrorMessage("Impossibile stabilire una connessione\ncol client ");
                break;

            case ClientErrorEventArgs.NETWORK_ERROR:
                ErrorMessage(" Connessione assente!\nAssicurarsi di essere collegato alla rete ");
                break;

            case ClientErrorEventArgs.CLIENT_ERROR:
                ErrorMessage(" ATTENZIONE!\nIl client non risponde ai messaggi ");
                break;

            default:
                ErrorMessage(" ATTENZIONE!\nErrore inaspettato");
                break;
            }
        }
示例#4
0
 private void StartListening()
 {
     try
     {
         IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(connectionParameter.Address), connectionParameter.TcpPort);
         listener = new TcpListener(endPoint);
         listener.Start();
         listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), this);
     }
     catch (SocketException se)
     {
         Trace.TraceError("SocketException in StartListening(). Stack trace:\n{0}\n", se.StackTrace);
         ClientErrorEventArgs args = new ClientErrorEventArgs()
         {
             ErrorCode = ClientErrorEventArgs.CONNECTION_ERROR
         };
         socketBroadcast.Close();
         workerBroadcast.CancelAsync();
         connection.ClientErrorMessageReceived(args);
         connection.CloseConnectionMessageRecived();
     }
 }
 internal void ClientErrorMessageReceived(ClientErrorEventArgs args)
 {
     EventHandler<ClientErrorEventArgs> handler = ClientError;
     if (handler != null)
     {
         handler(this, args);
     }
 }
 void connection_ClientError(object sender, ClientErrorEventArgs e)
 {
     Background = red;
 }
        void controlConnectionListener_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //Interrompo gli altri thread
            StopMouseListening();
            StopClipboardListening();
            ClientErrorEventArgs args = null;
            switch (innerState)
            {
                case InnerState.STOP_BY_NETWORK_ERROR:
                    connection.State = null;
                    args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.NETWORK_ERROR };
                    connection.ClientErrorMessageReceived(args);
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    return;

                case InnerState.STOP_BY_ERROR:
                    connection.State = null;
                    args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.CLIENT_ERROR };
                    connection.ClientErrorMessageReceived(args);
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    return;

                case InnerState.STOP_BY_USER:
                    connection.State = null;
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    return;
            }

            if (e.Error == null && e.Result != null)
            {
                string result = (string)e.Result;
                switch (result)
                {
                    case DEACTIVE_RESULT:
                        //cambio lo stato in connesso 
                        innerState = InnerState.STOP_BY_CONTROLLER;
                        connection.State = NextState(State.CONNECTED);
                        connection.ConnectClientMessageRecived(null, 0, 0);
                        forceButtonUp();
                        break;
                    case CLOSE_RESULT:
                        //passo allo stato disconnected
                        innerState = InnerState.STOP_BY_CONTROLLER;
                        connection.State = NextState(State.DISCONNECTED);
                        connection.DisconnectClientMessageRecived();
                        forceButtonUp();
                        if (tcpControlConnection != null)
                        {
                            stream.Close();
                            tcpControlConnection.Close();
                        }
                        break;

                    case EXTERNAL_CLOSE_RESULT:
                        
                        try
                        {
                            if (stream != null) { WriteMessage(stream, TipoComandoBytes.CLOSE_CONNECTION, 0, COMMAND_LENGHT); }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("Exception in controlConnectionListener_RunWorkerComplited(). Stack trace:\n{0}\n", ex.StackTrace);
                            if (!(ex is NetworkException || ex is IOException || ex is SocketException)) { throw; }
                        }
                        finally
                        {
                            if (tcpControlConnection != null)
                            {
                                stream.Close();
                                tcpControlConnection.Close();
                            }
                            connection.CloseConnectionMessageRecived();
                        }
                        break;

                    case NETWORK_ERROR_RESULT:
                        innerState = InnerState.STOP_BY_NETWORK_ERROR;
                        connection.State = null;
                        args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.NETWORK_ERROR };
                        connection.ClientErrorMessageReceived(args);
                        if (tcpControlConnection != null)
                        {
                            stream.Close();
                            tcpControlConnection.Close();
                        }
                        connection.CloseConnectionMessageRecived();
                        break;

                    case CLIENT_ERROR_RESULT:
                        innerState = InnerState.STOP_BY_ERROR;
                        connection.State = null;
                        args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.CLIENT_ERROR };
                        connection.ClientErrorMessageReceived(args);
                        if (tcpControlConnection != null)
                        {
                            stream.Close();
                            tcpControlConnection.Close();
                        }
                        connection.CloseConnectionMessageRecived();
                        break;

                    case GENERIC_ERROR_RESULT:
                        innerState = InnerState.STOP_BY_ERROR;
                        connection.State = null;
                        args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.GENERIC_ERROR };
                        connection.ClientErrorMessageReceived(args);
                        if (tcpControlConnection != null)
                        {
                            stream.Close();
                            tcpControlConnection.Close();
                        }
                        connection.CloseConnectionMessageRecived();
                        break;
                }
            }
        }
示例#8
0
 void connection_ClientError(object sender, ClientErrorEventArgs e)
 {
     Background = red;
 }
示例#9
0
        void controlConnectionListener_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //Interrompo gli altri thread
            ClientErrorEventArgs args = null;

            switch (innerState)
            {
            case InnerState.STOP_BY_NETWORK_ERROR:
                connection.State = null;
                args             = new ClientErrorEventArgs()
                {
                    ErrorCode = ClientErrorEventArgs.NETWORK_ERROR
                };
                connection.ClientErrorMessageReceived(args);
                if (tcpControlConnection != null)
                {
                    stream.Close();
                    tcpControlConnection.Close();
                }
                connection.CloseConnectionMessageRecived();
                return;

            case InnerState.STOP_BY_ERROR:
                connection.State = null;
                args             = new ClientErrorEventArgs()
                {
                    ErrorCode = ClientErrorEventArgs.CLIENT_ERROR
                };
                connection.ClientErrorMessageReceived(args);
                if (tcpControlConnection != null)
                {
                    stream.Close();
                    tcpControlConnection.Close();
                }
                connection.CloseConnectionMessageRecived();
                return;

            case InnerState.STOP_BY_USER:
                connection.State = null;
                if (tcpControlConnection != null)
                {
                    stream.Close();
                    tcpControlConnection.Close();
                }
                connection.CloseConnectionMessageRecived();
                return;
            }

            if (e.Error == null && e.Result != null)
            {
                string result = (string)e.Result;
                switch (result)
                {
                case ACTIVE_RESULT:
                    //cambio lo stato in connesso
                    connection.State = NextState(State.ACTIVE);
                    connection.ActiveClientMessageRecived();
                    break;

                case CLOSE_RESULT:
                    //passo allo stato disconnected
                    innerState       = InnerState.STOP_BY_CONTROLLER;
                    connection.State = NextState(State.DISCONNECTED);
                    connection.DisconnectClientMessageRecived();
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    break;

                case EXTERNAL_CLOSE_RESULT:    //Questo caso non dovrebbe accadere

                    try
                    {
                        if (stream != null)
                        {
                            WriteMessage(stream, TipoComandoBytes.CLOSE_CONNECTION, 0, COMMAND_LENGHT);
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Exception in controlConnectionListener_RunWorkerComplited(). Stack trace:\n{0}\n", ex.StackTrace);
                        if (!(ex is NetworkException || ex is IOException || ex is SocketException))
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        if (tcpControlConnection != null)
                        {
                            stream.Close();
                            tcpControlConnection.Close();
                        }
                        connection.CloseConnectionMessageRecived();
                    }
                    break;

                case NETWORK_ERROR_RESULT:
                    innerState       = InnerState.STOP_BY_NETWORK_ERROR;
                    connection.State = null;
                    args             = new ClientErrorEventArgs()
                    {
                        ErrorCode = ClientErrorEventArgs.NETWORK_ERROR
                    };
                    connection.ClientErrorMessageReceived(args);
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    break;

                case CLIENT_ERROR_RESULT:
                    innerState       = InnerState.STOP_BY_ERROR;
                    connection.State = null;
                    args             = new ClientErrorEventArgs()
                    {
                        ErrorCode = ClientErrorEventArgs.CLIENT_ERROR
                    };
                    connection.ClientErrorMessageReceived(args);
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    break;

                case GENERIC_ERROR_RESULT:
                    innerState       = InnerState.STOP_BY_ERROR;
                    connection.State = null;
                    args             = new ClientErrorEventArgs()
                    {
                        ErrorCode = ClientErrorEventArgs.GENERIC_ERROR
                    };
                    connection.ClientErrorMessageReceived(args);
                    if (tcpControlConnection != null)
                    {
                        stream.Close();
                        tcpControlConnection.Close();
                    }
                    connection.CloseConnectionMessageRecived();
                    break;
                }
            }
        }
        private void controlConnectionListener_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error == null && e.Result != null)
            {
                ClientErrorEventArgs args = null;
                string result = (string)e.Result;
                if (result.Equals(CONNECTED_RESULT))
                {
                    //Passo allo stato connesso
                    IConnectionState state = NextState(State.CONNECTED);
                    connection.State = state;
                    //chiudo il socket del broadcast xk deve essere
                    socketBroadcast.Close();
                    workerBroadcast.CancelAsync();
                    connection.ConnectClientMessageRecived(((IPEndPoint)tcpControlConnection.Client.RemoteEndPoint).Address.ToString(), width, height);
                    Trace.TraceInformation("Connesso.");
                }
                else
                {
                    //Altri casi
                    //Chiudo la connessione
                    tcpControlConnection.GetStream().Close();
                    tcpControlConnection.Close();
                    tcpControlConnection = null;
                    switch (result)
                    {
                        case STOPPED_RESULT:
                            connection.CloseConnectionMessageRecived();
                            break;

                        case NETWORK_ERROR_RESULT:
                            args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.NETWORK_ERROR };
                            connection.ClientErrorMessageReceived(args);
                            connection.CloseConnectionMessageRecived();
                            break;

                        case CLIENT_ERROR_RESULT:
                            args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.CLIENT_ERROR };
                            connection.ClientErrorMessageReceived(args);
                            connection.CloseConnectionMessageRecived();
                            break;

                        case GENERIC_ERROR_RESULT:
                            args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.GENERIC_ERROR };
                            connection.ClientErrorMessageReceived(args);
                            connection.CloseConnectionMessageRecived();
                            break;
                        case LOGIN_ERROR_RESULT:
                            listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), this);
                            return;
                    }
                }
                listener.Stop();

            }

        }
 private void StartListening()
 {
     try
     {
         IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(connectionParameter.Address), connectionParameter.TcpPort);
         listener = new TcpListener(endPoint);
         listener.Start();
         listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), this);
     }
     catch (SocketException se)
     {
         Trace.TraceError("SocketException in StartListening(). Stack trace:\n{0}\n", se.StackTrace);
         ClientErrorEventArgs args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.CONNECTION_ERROR };
         socketBroadcast.Close();
         workerBroadcast.CancelAsync();
         connection.ClientErrorMessageReceived(args);
         connection.CloseConnectionMessageRecived();
                       
     }
 }
 void workerBroadcast_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error == null && e.Result != null)
     {
         if (e.Result.Equals(CLIENT_ERROR_RESULT))
         {
             ClientErrorEventArgs args = new ClientErrorEventArgs() { ErrorCode = ClientErrorEventArgs.CONNECTION_ERROR };
             connection.ClientErrorMessageReceived(args);
         }
     }
 }
 void connection_ClientError(object sender, ClientErrorEventArgs e)
 {
     switch (e.ErrorCode)
     {
         case ClientErrorEventArgs.CONNECTION_ERROR:
             ErrorMessage("Impossibile stabilire una connessione\ncol client ");
             break;
         case ClientErrorEventArgs.NETWORK_ERROR:
             ErrorMessage(" Connessione assente!\nAssicurarsi di essere collegato alla rete ");
             break;
         case ClientErrorEventArgs.CLIENT_ERROR:
             ErrorMessage(" ATTENZIONE!\nIl client non risponde ai messaggi ");
             break;
         default:
             ErrorMessage(" ATTENZIONE!\nErrore inaspettato");
             break;
     }
 }
示例#14
0
        private void controlConnectionListener_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error == null && e.Result != null)
            {
                ClientErrorEventArgs args = null;
                string result             = (string)e.Result;
                if (result.Equals(CONNECTED_RESULT))
                {
                    //Passo allo stato connesso
                    IConnectionState state = NextState(State.CONNECTED);
                    connection.State = state;
                    //chiudo il socket del broadcast xk deve essere
                    socketBroadcast.Close();
                    workerBroadcast.CancelAsync();
                    connection.ConnectClientMessageRecived(((IPEndPoint)tcpControlConnection.Client.RemoteEndPoint).Address.ToString(), width, height);
                    Trace.TraceInformation("Connesso.");
                }
                else
                {
                    //Altri casi
                    //Chiudo la connessione
                    tcpControlConnection.GetStream().Close();
                    tcpControlConnection.Close();
                    tcpControlConnection = null;
                    switch (result)
                    {
                    case STOPPED_RESULT:
                        connection.CloseConnectionMessageRecived();
                        break;

                    case NETWORK_ERROR_RESULT:
                        args = new ClientErrorEventArgs()
                        {
                            ErrorCode = ClientErrorEventArgs.NETWORK_ERROR
                        };
                        connection.ClientErrorMessageReceived(args);
                        connection.CloseConnectionMessageRecived();
                        break;

                    case CLIENT_ERROR_RESULT:
                        args = new ClientErrorEventArgs()
                        {
                            ErrorCode = ClientErrorEventArgs.CLIENT_ERROR
                        };
                        connection.ClientErrorMessageReceived(args);
                        connection.CloseConnectionMessageRecived();
                        break;

                    case GENERIC_ERROR_RESULT:
                        args = new ClientErrorEventArgs()
                        {
                            ErrorCode = ClientErrorEventArgs.GENERIC_ERROR
                        };
                        connection.ClientErrorMessageReceived(args);
                        connection.CloseConnectionMessageRecived();
                        break;

                    case LOGIN_ERROR_RESULT:
                        listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), this);
                        return;
                    }
                }
                listener.Stop();
            }
        }