Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Dear All,

I am developing a chat application in .net.
it worked well on localhost. but when i am trying to work on two pc it is not working.
please help me to solve this problem.

this code is to get data from server.

C#
private void btnGetMsg_Click(object sender, EventArgs e)
        {
            
            IPHostEntry ipHostInfo = Dns.Resolve("192.168.1.6");
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 1000);
            TcpClient c = new TcpClient(remoteEP);
            int aa = c.ReceiveBufferSize;
            NetworkStream ns = c.GetStream(); //get stream
            byte[] buf = new byte[100]; //create byte array to receive data
            ns.Read(buf, 0, 100);  // read data from stream into byte array
            string st = System.Text.Encoding.ASCII.GetString(buf); // convert byte array to string
            if (st != "")
            {
                listBox1.Items.Add(string.Concat("Server Said: ", st));
            }
        }



this code is to send data for client.

C#
private void button2_Click(object sender, EventArgs e)
      {

          TcpListener l = new TcpListener(1000);
          l.Start();   // start listener

          TcpClient c = l.AcceptTcpClient();   // wait for client to make request
          NetworkStream ns = c.GetStream();  // access steam to send data to client.

          string st = textBox1.Text;   // get system date and convert it to string

          listBox1.Items.Add(string.Concat("Server Said: ", textBox1.Text));
          byte[] buf = System.Text.Encoding.ASCII.GetBytes(st);  // convert string to an array of bytes
          ns.Write(buf, 0, st.Length);  // write to stream
          l.Stop();

      }
Posted
Comments
Mehdi Gholam 24-Sep-11 3:55am    
Check your firewall settings.
Richard MacCutchan 24-Sep-11 5:59am    
You should add some code to check the status returns from your various system calls to check for errors. It is not easy to figure out why this is not working without some more information.
yogiCsharp 13-Oct-11 7:59am    
Code looks fine, you should provide the exception detail if exception is occurring.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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