anish99virgo 0 Newbie Poster

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

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.

[B]1 Server Code[/B]

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

2 [B][U]SERVICE CLASS
[/U][/B]
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 [B][U]CLIENT PART----[/U][/B]

  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");} } }


  [B] FORM2[/B]
 
  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);
                }
            }
        }

   [B][U] INTERFACE IMPLEMENTED IN CLIENT PART[/U][/B]
      namespace Trial
{
  public   interface Class1
    {
        void adduser(string name);

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

        string getmessage(string u);

        ICollection<string> users();
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.