Chat server and client
I want to make a chat server using C#.net as the coding language and and a chat client. I know several open source full fledged chatting servers are available. But i want to create a one. Please help me out. and please help how to create a database. and what are the essential fields for a database.

Lalit MRank #1,186 · 1.5K reputationPosted Nov 16, 2009, 12:57 AM EST
using System; using System.Windows.Forms; using System.Text; using System.Net.Sockets ; using System.Threading; namespace WindowsApplication2 { public partial class Form1 : Form { System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient(); NetworkStream serverStream = default(NetworkStream); string readData = null; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox2.Text + "$"); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush(); } private void button2_Click(object sender, EventArgs e) { readData = "Conected to Chat Server ..."; msg(); clientSocket.Connect("127.0.0.1", 8888); serverStream = clientSocket.GetStream(); byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox3.Text + "$"); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush(); Thread ctThread = new Thread(getMessage); ctThread.Start(); } private void getMessage() { while (true) { serverStream = clientSocket.GetStream(); int buffSize = 0; byte[] inStream = new byte[10025]; buffSize = clientSocket.ReceiveBufferSize; serverStream.Read(inStream, 0, buffSize); string returndata = System.Text.Encoding.ASCII.GetString(inStream); readData = "" + returndata; msg(); } } private void msg() { if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg)); else textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + readData; } } }