C# .NET - chat application - Asked By Dilip Sharma on 17-Nov-11 08:02 AM

hi friend i want to develop simple chat window application like (Nimbuzz , google Talk)  using c# .net....

I need some idea about it....

 i know i need to host my data base in server
which i can do.....

what other i need to do....

Plse suggest....

first i want basic ...
where 2 person can chat....

Kirtan Patel replied to Dilip Sharma on 17-Nov-11 08:16 AM
As Just A Guidance
chat application does not require any database if you want to provide online chat kind of program . database will only require if you want to store history of chat both user done or offline messenger kind of facility .to make Chat application you need to have Knowledge of TCP Protocol not much but need that .you need to work with Socket Programming for this purpose you can find socket programming related classes in
where you have two type of communication choices according to QOS you select TCP/UDP Socket
Dilip Sharma replied to Kirtan Patel on 17-Nov-11 08:18 AM
then where we store user information.....

and how we will know which user have which friends  ? ? ? ?  
Kirtan Patel replied to Dilip Sharma on 17-Nov-11 08:26 AM
providing that kind of personalization feature in chat application requires use of database like friends Profile like yahoo Provides  else chat application is able to communicate using IP addressing from Network Layer of the TCP/IP Stack.features like gtalk /yahoo requires database and alos you required to use MultiThreading if Multiple users are interacting at same time like Group Chat using Class D IP Addresses.

Dilip Sharma replied to Kirtan Patel on 17-Nov-11 08:27 AM
ok ... thanks for suggestion... i will work on this.....

if u know some useful link plse let me know.....

Kirtan Patel replied to Dilip Sharma on 17-Nov-11 08:39 AM
Here is some sample program you can refer to for Socket Programming to pass a String to another computer using InterProcess Communication facility (Socket programming ) There are Two part Server and Client ie you can assume as Two user's .

Server Program 

using System;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication1
  class Program
    static void Main(string[] args)
      TcpListener serverSocket = new TcpListener(8888);
      int requestCount = 0;
      TcpClient clientSocket = default(TcpClient);
      Console.WriteLine(" >> Server Started");
      clientSocket = serverSocket.AcceptTcpClient();
      Console.WriteLine(" >> Accept connection from client");
      requestCount = 0;
      while ((true))
          requestCount = requestCount + 1;
          NetworkStream networkStream = clientSocket.GetStream();
          byte[] bytesFrom = new byte[10025];
          networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
          string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
          dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
          Console.WriteLine(" >> Data from client - " + dataFromClient);
          string serverResponse = "Server response " + Convert.ToString(requestCount);
          Byte[] sendBytes = Encoding.ASCII.GetBytes(serverResponse);
          networkStream.Write(sendBytes, 0, sendBytes.Length);
          Console.WriteLine(" >> " + serverResponse);
        catch (Exception ex)
      Console.WriteLine(" >> exit");

Client Program
namespace WindowsApplication1
  public partial class Form1 : Form
    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    public Form1()
    private void Form1_Load(object sender, EventArgs e)
      msg("Client Started");
      clientSocket.Connect("", 8888);
      label1.Text = "Client Socket Program - Server Connected ...";
    private void button1_Click(object sender, EventArgs e)
      NetworkStream serverStream = clientSocket.GetStream();
      byte[] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
      serverStream.Write(outStream, 0, outStream.Length);
      byte[] inStream = new byte[10025];
      serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
      string returndata = System.Text.Encoding.ASCII.GetString(inStream);
      msg("Data from Server : " + returndata);
    public void msg(string mesg)
      textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;