This class represents a connection to a remote host. It is possible to notify this host with messages that extends upon the "AbstractMessage" class. HOW TO USE: * Initialize the class with needed parameters (see constructor) * Call "Start()" method to start listening for incoming messages and start to write messages * Whenever a message is received from the server, the OnMessageReceived callback is called. * Whenever a message is received but in a corrupted format, the OnMessageFailed is called. * If the connection to the server fails, the OnConnectionFailed is called. The underlying connection will automatically be closed, so you do not need to call the stop method if this delegate is fired. * Writing to the server is non-blocking. All it does is to place the message into a buffer that is then handled by another thread.
コード例 #1
0
 public RespondToInitRequestMessage(Dispatcher disp, TaskHandler handler, ClientConnectionList list, ClientConnection client, InitRequestMessage msg)
     : base(disp, handler)
 {
     ClientConnectionList = list;
     ClientConnection = client;
     InitRequestMessage = msg;
 }
コード例 #2
0
 public RemoveClientFromUserListTask(Dispatcher disp, TaskHandler handler, ClientConnectionList list, ClientConnection client, ObservableCollection<UserLocation> locs)
     : base(disp, handler)
 {
     ClientConnectionList = list;
     ClientConnection = client;
     UserLocations = locs;
 }
コード例 #3
0
 public RespondToGeoPointMessageTask(Dispatcher disp, TaskHandler handler, ClientConnectionList list, ClientConnection client, ObservableCollection<UserLocation> locs, GeoPointMessage msg)
     : base(disp, handler)
 {
     ClientConnectionList = list;
     ClientConnection = client;
     GeoPointMessage = msg;
     UserLocations = locs;
 }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: bakacaptain/istalkapp
        public void OnConnectionFailed(Object sender, ClientConnection.ConnectionFailedEventArgs args)
        {
            RemoveClientFromUserListTask task = new RemoveClientFromUserListTask(
                Dispatcher,
                TaskHandler.DispatcherAsync,
                UserList,
                sender as ClientConnection,
                UserLocations);

            task.RunWorkerCompleted += TaskCompleted;
            task.BeginExecute();
        }
コード例 #5
0
 /// <summary>
 /// Constructor for MessageWriter.
 /// </summary>
 /// <param name="inner">This is the ClientConnection that this class is inside.</param>
 /// <param name="connection">This is the TCPConnection that the ClientConnection is connected to.</param>
 /// <param name="MessageFailed">A delegate representing the method to be called whenever this MessageWriter
 /// fails to write a message into it's underlying TCPConnection.</param>
 public MessageWriter(ClientConnection inner, TCPConnection connection)
 {
     this.inner = inner;
     this.connection = connection;
 }
コード例 #6
0
 public AddClientToUserListTask(Dispatcher disp, TaskHandler handler, ClientConnectionList list, ClientConnection client)
     : base(disp, handler)
 {
     ClientConnectionList = list;
     ClientConnection = client;
 }
コード例 #7
0
        /// <summary>
        /// Method listening for incoming connections.
        /// </summary>
        private void Go()
        {
            try
            {
                while (true)
                {
                    try
                    {
                        TCPConnection con = listener.waitForConnection();
                        ClientConnection client = new ClientConnection(con);
                        client.MessageFailed += MessageFailed;
                        client.MessageReceived += MessageReceived;
                        client.ConnectionFailed += ConnectionFailed;

                        if (InitialConnectionSuccess != null)
                        {
                            InitialConnectionSuccessEventArgs args = new InitialConnectionSuccessEventArgs();
                            args.Client = client;
                            InitialConnectionSuccess(this, args);
                        }
                    }
                    catch (SocketException e)
                    {
                        if (InitialConnectionFailed != null)
                        {
                            InitialConnectionFailedEventArgs args = new InitialConnectionFailedEventArgs();
                            args.Cause = e;
                            InitialConnectionFailed(this, args);
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        if (InitialConnectionFailed != null)
                        {
                            InitialConnectionFailedEventArgs args = new InitialConnectionFailedEventArgs();
                            args.Cause = e;
                            InitialConnectionFailed(this, args);
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                // do something ?
            }
        }
コード例 #8
0
ファイル: App.xaml.cs プロジェクト: bakacaptain/istalkapp
        public void OnMessageReceived(Object sender, ClientConnection.MessageReceivedEventArgs args)
        {
            ClientConnection client = sender as ClientConnection;
            if (args.Message is InitRequestMessage)
            {
                RespondToInitRequestMessage task = new RespondToInitRequestMessage(
                    Dispatcher,
                    TaskHandler.DispatcherAsync,
                    UserList,
                    client,
                    args.Message as InitRequestMessage);

                task.RunWorkerCompleted += TaskCompleted;
                task.BeginExecute();
            }
            else if (args.Message is GeoPointMessage)
            {
                RespondToGeoPointMessageTask task = new RespondToGeoPointMessageTask(
                    Dispatcher,
                    TaskHandler.DispatcherAsync,
                    UserList,
                    client,
                    UserLocations,
                    args.Message as GeoPointMessage);

                task.RunWorkerCompleted += TaskCompleted;
                task.BeginExecute();
            }
            else if (args.Message is MultipleGeoPointRequestMessage)
            {
                MultipleGeoPointResponseMessage msg = null;
                lock (UserLocations)
                {
                    msg = new MultipleGeoPointResponseMessage(UserLocations.ToList());
                }
                client.Notify(msg);
            }
        }
コード例 #9
0
ファイル: App.xaml.cs プロジェクト: bakacaptain/istalkapp
 public void OnMessageFailed(Object sender, ClientConnection.MessageFailedEventArgs args)
 {
 }