Inheritance: MarshalByRefObject
コード例 #1
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            // Creates a client object that 'lives' here on the client.
            _CallbackSink = new CallbackSink();

            // Hook into the event exposed on the Sink object so we can transfer a server message through back to this class.
            _CallbackSink.OnHostToClient += new delegateCommsInfo(CallbackSink_OnHostToClient);

            // Register a client channel so the server can communicate back - it needs a channel opened in order to make
            // the callback to the CallbackSink object that is anchored on the client!
            HttpChannel channel = new HttpChannel(9003);

            ChannelServices.RegisterChannel(channel, false);

            // Now create a transparent proxy to the server component
            object obj = Activator.GetObject(typeof(RemotingComms), "http://127.0.0.1:9000/RUETalk");

            // Cast returned object
            _ServerTalk = (RemotingComms)obj;

            // Register the client on the server with info on our callback to the client sink.
            var clientGuid = System.Guid.NewGuid();

            _ServerTalk.RegisterHostToClient(clientGuid.ToString(), new delegateCommsInfo(_CallbackSink.HandleToClient));

            // Make sure we can't register again!
            btnRegister.Enabled = false;
            btnRegister.Text    = "Registered";
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: mono/gert
	static int Main ()
	{
		receivedMsg = new AutoResetEvent (false);

		HttpChannel channel = new HttpChannel (0);
#if NET_2_0
		ChannelServices.RegisterChannel (channel, false);
#else
		ChannelServices.RegisterChannel (channel);
#endif

		ServerTalk _ServerTalk = (ServerTalk) Activator.GetObject (typeof (ServerTalk), "http://localhost:8081/hydraplus.soap");

		CallbackSink _CallbackSink = new CallbackSink ();
		_CallbackSink.OnHostToClient += new delCommsInfo (CallbackSink_OnHostToClient);

		_ServerTalk.RegisterHostToClient ("Me", 0, new delCommsInfo (_CallbackSink.HandleToClient));

		string messageSent = Guid.NewGuid ().ToString ();

		_ServerTalk.SendMessageToServer (new CommsInfo ("Me", "txt", messageSent));

		if (receivedMsg.WaitOne (5000, false)) {
			Assert.AreEqual (messageReceived, messageSent, "#1");
			return 0;
		} else {
			return 1;
		}
	}
コード例 #3
0
        /// <summary>
        /// When the user clicks the login button we use the data entered by the user to try to login
        /// Checks are performed to assure that the user input is correct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            /* get the user name */
            this.username = textBoxUserName.Text;
            /* if there is no input */
            if (this.username.Length == 0)
            {
                /* show an error dialog when the user does not enter the correct data */
                MessageBox.Show("Please enter a valid user name!",
                                "Invalid user name",
                                MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
                /* focus the text box */
                this.textBoxUserName.Focus();
                return;
            }
            /* a default port number */
            int portNumber = 12346;

            /* check if the port is correct */
            if (textBoxPortNumber.Text.Length > 0)
            {
                try
                {
                    /* parse it to int */
                    portNumber = Int32.Parse(textBoxPortNumber.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Please enter a valid port number!",
                                    "Invalid port number",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Exclamation);
                    return;
                }
            }
            /* create a callback sink for the client */
            messagesCallback = new CallbackSink();
            /* we attach the delagate so that we can get messages from the server through it */
            messagesCallback.fromServerToUser += new delegateCommunication(delegateFromServerToUser);
            try
            {
                /* because of the delegate we need a channel from the server to the client */
                channel = new TcpChannel(portNumber);
                /* register it */
                ChannelServices.RegisterChannel(channel, false);
                /* create the reference */
                serverReference = (ServerCommunicator)Activator.GetObject(typeof(ServerCommunicator),
                                                                          "tcp://localhost:12345/ServerAccess");
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
            }
            /* now we can use the reference to login */
            serverReference.loginUserAndAdd(this.textBoxUserName.Text, new delegateCommunication(messagesCallback.HandleToClient));
            /* prepare de GUI */
            initializeForChat();
        }