Click here to Skip to main content
15,885,918 members

Error in Chat Application C#

Member 7789837 asked:

Open original thread
Hey! Well I am naive to C# Programming. I had tried a Chat Server in C# comprising of three applications..

1 Server- TCP Server with port no. 8085

2 Service Class- Providing the services

3 Client- accessing Services

<color>The error is that in Client Application whenever i run it, the exe file gets hang & not responding message is generated.. by windows. It doesnot provide me any exceptions.. So dont know where the error is! PLease help me!!! Its Urgent!! THanks in advance..!!

Server is running ok.. no problem in it.

I am pasting the code also.. for each of the 3 applications i have build.


1 Server Code

I had used TCP server to provide the necessary settings with port 8085 & its running properly.

2<color> SERVICE CLASS

namespace ServiceClass
{       public class Class1 : MarshalByRefObject
        {
            Dictionary<string, string> Dc = new Dictionary<string, string>();
            public void adduser(string name)
            {
                Dc.Add(name, " ");
            }
            public void setmessage(string from, string to, string message)
            {
                Dc[from] = Dc[from] + from + ":" + message + Environment.NewLine;
                Dc[to] = Dc[to] + from + ":" + message + Environment.NewLine;
            }
            public string getmessage(string u)
            {
                return Dc[u];
            }
            public ICollection<string> users()
            {
                return Dc.Keys;
            }   }}

3 <color> CLIENT PART----


FORM 1


namespace Trial
{
 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static string UserName;
        private void button1_Click_1(object sender, EventArgs e)
        {
            UserName = textBox1.Text;
            Form2 ob = new Form2();
            ob.Show();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ServiceClass.Class1 obj = (ServiceClass.Class1)Activator.GetObject(typeof(Class1), "Tcp://localhost:8085/ServiceClass");} } }


FORM2

namespace Trial
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        ServiceClass.Class1 obj = (ServiceClass.Class1)Activator.GetObject(typeof(Class1), "Tcp://localhost:8085/ServiceClass");
       
        private void Form2_Load_1(object sender, EventArgs e)
        {
            
            label1.Text = Form1.UserName;
            obj.adduser(Form1.UserName);
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            obj.setmessage(label1.Text, comboBox1.SelectedItem.ToString(), textBox1.Text);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            ICollection<string> ic = obj.users();
            foreach (string s in ic)
            {
                if (comboBox1.Items.Contains(s))
                {
                    comboBox1.Items.Add(s);
                }
                if (comboBox1.SelectedItem != null)
                {
                    textBox1.Text = obj.getmessage(Form1.UserName);
                }
            }
        }

INTERFACE IMPLEMENTED IN CLIENT PART
namespace Trial
{
  public   interface Class1
    {
        void adduser(string name);

        void setmessage(string from, string to, string message);

        string getmessage(string u);

        ICollection<string> users();
    }
}


[edit]Code blocks sorted out - OriginalGriff[/edit]
Tags: C# 3.5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900