.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Required code for Chatting multiple users..... in C# .net Windows application

Posted By: Vishu     Posted Date: July 28, 2011    Points:5   Category :C#
Can anyone Help..........
Thanks in Advance.........

Responses
Author: Dhiraj Ranka             
Posted Date: July 28, 2011     Points: 20   
Author: Sasi Prabhu             
Posted Date: July 29, 2011     Points: 20   


Refer :

http://www.codeproject.com/KB/cs/LanChat.aspx

http://www.codeproject.com/KB/IP/TCPIPChat.aspx

Thanks & Regards,
Sasi Prabhu.
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

try these voice chat application as

http://www.codeproject.com/KB/WPF/WPFTwain.aspx

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

try these peoject for ur reference as


http://www.java2s.com/Code/CSharp/Network/ChatApplication.htm

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

A Chat Client/Server Program for C#

The client:

using System.IO;
using System.Net;
using System;
using System.Threading;
using N = System.Net;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;

class TalkUser {

static Form talk;
static N.Sockets.TcpClient TC;

[DllImport("kernel32.dll")]
private static extern void ExitProcess(int a);

public static void Main() {
talk = new Form();
talk.Text = "TalkUser - The OFFICIAL TalkServ Client";
talk.Closing += new CancelEventHandler(talk_Closing);
talk.Controls.Add(new TextBox());
talk.Controls[0].Dock = DockStyle.Fill;
talk.Controls.Add(new TextBox());
talk.Controls[1].Dock = DockStyle.Bottom;
((TextBox)talk.Controls[0]).Multiline = true;
((TextBox)talk.Controls[1]).Multiline = true;
talk.WindowState = FormWindowState.Maximized;
talk.Show();
((TextBox)talk.Controls[1]).KeyUp += new KeyEventHandler(key_up);
TC = new N.Sockets.TcpClient();
TC.Connect("IP OF A SERVER HERE",4296);
Thread t = new Thread(new ThreadStart(run));
t.Start();
while(true) {
Application.DoEvents();
}
}

private static void talk_Closing(object s, CancelEventArgs e) {
e.Cancel = false;
Application.Exit();
ExitProcess(0);
}

private static void key_up(object s,KeyEventArgs e) {
TextBox TB = (TextBox)s;
if(TB.Lines.Length>1) {
StreamWriter SW = new StreamWriter(TC.GetStream());
SW.WriteLine(TB.Text);
SW.Flush();
TB.Text = "";
TB.Lines = null;
}
}

private static void run() {
StreamReader SR = new StreamReader(TC.GetStream());
while(true) {
Application.DoEvents();
TextBox TB = (TextBox)talk.Controls[0];
TB.AppendText(SR.ReadLine()+"\r\n");
TB.SelectionStart = TB.Text.Length;
}
}
}



And the server:


using System.IO; 
using System.Net;
using System;
using System.Threading;
using N = System.Net;
using System.Collections;

class TalkServ {

System.Net.Sockets.TcpListener server;
public static Hashtable handles;
public static Hashtable handleByConnect;

public static void Main() {
TalkServ TS = new TalkServ();
}

public TalkServ() {
handles = new Hashtable(100);
handleByConnect = new Hashtable(100);
server = new System.Net.Sockets.TcpListener(4296);
while(true) {
server.Start();
if(server.Pending()) {
N.Sockets.TcpClient connection = server.AcceptTcpClient();
Console.WriteLine("Connection made");
BackForth BF = new BackForth(connection);
}
}
}

public static void SendToAll(string name,string msg) {
StreamWriter SW;
ArrayList ToRemove = new ArrayList(0);
N.Sockets.TcpClient[] tc = new N.Sockets.TcpClient[TalkServ.handles.Count];
TalkServ.handles.Values.CopyTo(tc,0);
for(int i=0;i<tc.Length;i++) {
try {
if(msg.Trim()==""||tc[i]==null)
continue;
SW = new StreamWriter(tc[i].GetStream());
SW.WriteLine(name + ": " + msg);
SW.Flush();
SW = null;
} catch(Exception e44) { e44 = e44;
string g = (string) TalkServ.handleByConnect[tc[i]];
TalkServ.SendSysMsg("** " + g + " ** HAS LEFT US.");
TalkServ.handles.Remove(g);
TalkServ.handleByConnect.Remove(tc[i]);
}
}
}

public static void SendSysMsg(string msg) {
StreamWriter SW;
ArrayList ToRemove = new ArrayList(0);
N.Sockets.TcpClient[] tc = new N.Sockets.TcpClient[TalkServ.handles.Count];
TalkServ.handles.Values.CopyTo(tc,0);
for(int i=0;i<tc.Length;i++) {
try {
if(msg.Trim()==""||tc[i]==null)
continue;
SW = new StreamWriter(tc[i].GetStream());
SW.WriteLine(msg);
SW.Flush();
SW = null;
} catch(Exception e44) { e44 = e44;
TalkServ.handles.Remove(TalkServ.handleByConnect[tc[i]]);
TalkServ.handleByConnect.Remove(tc[i]);
}
}
}
}//end of class TalkServ

class BackForth {
N.Sockets.TcpClient client;
System.IO.StreamReader SR;
System.IO.StreamWriter SW;
string handle;

public BackForth(System.Net.Sockets.TcpClient c) {
client = c;
Thread t = new Thread(new ThreadStart(init));
t.Start();
}

private string GetHandle() {
SW.WriteLine("What is your handle? ");
SW.Flush();
return SR.ReadLine();
}

private void run() {
try {
string l = "";
while(true) {
l = SR.ReadLine();
TalkServ.SendToAll(handle,l);
}
} catch(Exception e44) { Console.WriteLine(e44); }
}

private void init() {
SR = new System.IO.StreamReader(client.GetStream());
SW = new System.IO.StreamWriter(client.GetStream());
SW.WriteLine("WELCOME TO TalkServ! Be Nice!");
//SW.WriteLine("What is your handle? ");
//SW.Flush();
handle = GetHandle();
while(TalkServ.handles.Contains(handle)) {
SW.WriteLine("ERR - Handle already exists!");
handle = GetHandle();
}
TalkServ.handles.Add(handle,client);
TalkServ.handleByConnect.Add(client,handle);
TalkServ.SendSysMsg("** " + handle + " ** HAS JOINED US.");
SW.WriteLine("Now Talking.....\r\n-------------------------------");
SW.Flush();
Thread t = new Thread(new ThreadStart(run));
t.Start();
}
}


Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Gowthammanju             
Posted Date: July 29, 2011     Points: 20   

keep viewing these link as


http://www.giantflyingsaucer.com/blog/?p=60

http://www.daveoncsharp.com/2009/08/csharp-chat-application-over-asynchronous-udp-sockets-part-2/

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Vishu             
Posted Date: July 30, 2011     Points: 20   

thank you very much friend.......
Gowthammanju .........your links helped me too much....
Can u help me whether video chat is possible on lan for windows C# app.if so then how pls awaiting for your answer.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend