Note that there are some explanatory texts on larger screens.

plurals
  1. PORemote Client-Server Application cannot accept incoming messages
    primarykey
    data
    text
    <p>In my .Net class, we are making a simple chat application. Our professor gave us a sample code as follows:</p> <p>SERVER:</p> <pre><code>TcpChannel channel = new TcpChannel(8085); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "myobject", WellKnownObjectMode.Singleton); Console.ReadLine(); </code></pre> <p>CLIENT:</p> <pre><code>TcpChannel channel = new TcpChannel(); ChannelServices.RegisterChannel(channel); RemoteObject remoteObject = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8085/myobject"); remoteObject.PrintMessage("Hello world!"); Console.ReadLine(); </code></pre> <p>REMOTE OBJECT:</p> <pre><code>[Serializable] public class RemoteObject : MarshalByRefObject { public void PrintMessage() { Console.Write("Hello World!"); Console.ReadLine(); } } </code></pre> <p>With this code, it basically prints a "Hello World" message on the server console screen each time the client is run. However, we do not understand how this works since he didn't fully explain what each line does. We only know about the channels. The catch is that with these codes, we are to create a Windows Form of a chat. We were able to make this application send a message provided by the user but we can't figure out how we can do it in a windows form since we do not understand the code to start with.</p> <p>If anyone can help us with some pointers and guidelines on how we can do this in a Windows Form, please let us know. Any input is appreciated.</p> <p>If this would help in any way, the code below is as far as we could go as of now:</p> <pre><code>public partial class Form1 : Form { RemoteObject ro; public Form1() { InitializeComponent(); TcpChannel serverChannel = new TcpChannel(8085); ChannelServices.RegisterChannel(serverChannel, true); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "myobject", WellKnownObjectMode.Singleton); } private void btnSend_Click(object sender, EventArgs e) { try { ro = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://" + txtIpAddress.Text + ":8085/myobject"); ro.PrintMessage(txtMessage.Text); txtChatArea.AppendText(System.Environment.MachineName + ": " + txtMessage.Text + "\n"); txtMessage.Clear(); } catch (SystemException error) { MessageBox.Show("Error 101: " + error.Message, "Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } </code></pre> <p>The code above basically asks for the IP Address of the second party (the party you are chatting with) and then provided are two text boxes - one is for displaying the conversation (multilined) while the other is for accepting messages. This code can send message to the server. But still, it cannot accept any incoming message from other parties.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload