Hi,
i need some help please on creating a chat app in VS2005. this can be very plain its liker a one to one chat app via internet.
this is my code i have thus far pls tell if im on the right track:
oh and i wrote this so you chat with yourself first this is only temporarily tho and then i need to figure it out how to get it working for two people lol
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using System.ComponentModel;
using System.Net;
using System.Drawing.Drawing2D;
namespace MyTalk
{
public partial class Chat : DevComponents.DotNetBar.Office2007Form
{
private TcpClient objClient;
private Thread thdListener;
private TcpListener objListener;
private string strFriend;
private string strMe;
IPAddress ipadd;
public delegate void Invoker(String t);
public Chat()
{
strFriend = "10.0.1.166";
ipadd = Dns.GetHostEntry(strFriend).AddressList[0];
strMe = "Me";
thdListener = new Thread(new ThreadStart(this.Listen));
thdListener.Start();
InitializeComponent();
}
private void Listen()
{
string strTemp = "";
objListener = new TcpListener(ipadd,1000);
objListener.Start();
do
{
TcpClient objClient = objListener.AcceptTcpClient();
StreamReader objReader = new StreamReader(objClient.GetStream());
while (objReader.Peek() != -1)
{
strTemp += Convert.ToChar(objReader.Read()).ToString();
}
object[] objParams = new object[] { strTemp };
strTemp = "";
this.Invoke(new Invoker(this.ShowMessage), objParams);
} while (true != false);
}
private void ShowMessage(String t)
{
rtbMessage.Text += strFriend + ": " + t + "\n";
}
private void btExit_Click(object sender, EventArgs e)
{
objListener.Stop();
Application.Exit();
Environment.Exit(0);
}
private void btSend_Click(object sender, EventArgs e)
{
rtbMessage.Text += strMe + ": " + rtbType.Text + "\n";
objClient = new TcpClient(strFriend, 1002);
StreamWriter w = new StreamWriter(objClient.GetStream());
w.Write(rtbType.Text + "\n");
w.Flush();
objClient.Close();
rtbType.Text = "";
}