Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everyone!

I'm creating a windows chat application using visual studio 2008 C#. Can someone please create a step by step process/codes in creating one. I already have 3 forms login, register, chatuser, chatbox. Please help me in creating my windows chat application. Thanks in advance!
Posted
Comments
CPallini 14-Aug-14 5:01am    
And where is the fun, then?
Member 14092290 3-Jan-19 7:51am    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace New_Team_project
{
public partial class Form1 : Form
{
Socket sck;
EndPoint eplocal, epRemote;
public Form1()
{
InitializeComponent();
sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
textlocalip.Text = GetLocalIP();
textfriendsip.Text = GetLocalIP();
}
private string GetLocalIP()

{

IPHostEntry host;

host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)

{

if (ip.AddressFamily == AddressFamily.InterNetwork)

{

return ip.ToString();

}

}

return "127.0.0.1";

}
private void Messagecallback(IAsyncResult aResult)
{

try

{

int size = sck.EndReceiveFrom(aResult, ref epRemote);
if (size > 0)
{
byte[] receivedData = new byte[1464];
receivedData = (byte[])aResult.AsyncState;
ASCIIEncoding eEncoding = new ASCIIEncoding();

string receivedMessage = eEncoding.GetString(receivedData);
listMessage.Items.Add("Friend: " + receivedMessage);
}
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(Messagecallback), buffer);

}

catch (Exception exp)

{

MessageBox.Show(exp.ToString());

}

}

private void button1_Click(object sender, EventArgs e)
{
try

{

eplocal = new IPEndPoint(IPAddress.Parse(textlocalip.Text), Convert.ToInt32(textlocalport.Text));
sck.Bind(eplocal);

eplocal = new IPEndPoint(IPAddress.Parse(textfriendsip.Text), Convert.ToInt32(textfriendsport.Text));
sck.Connect(epRemote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(Messagecallback), buffer);



button1.Text = "connected";
button1.Enabled = false;
button2.Enabled = true;
textMessage.Focus();

}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void button2_Click(object sender, EventArgs e)
{
try
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] msg = new byte[1500];
msg = enc.GetBytes(textMessage.Text);
sck.Send(msg);
listMessage.Items.Add("You:"+textMessage.Text);
textMessage.Clear();


}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

1 solution

Dear Member 10994115,

Windows-base IP address base Chatting application design, fruther enhancement you can do by you own.


This link will help you.

http://www.c-sharpcorner.com/UploadFile/97ec13/how-to-make-a-chat-application-in-C-Sharp/[^]

Thank You,
Manoj Kalla
 
Share this answer
 

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