高分求局域网聊天程序源代码

adun_ 2005-03-05 11:22:57
求一个聊天程序源代码用来学习,要想QQ那样,有服务器的和客户端的。谢谢~~
...全文
443 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
胡歌 2010-06-18
  • 打赏
  • 举报
回复
up,顶
adun_ 2005-03-07
  • 打赏
  • 举报
回复
谢谢大家啊~
sswv 2005-03-06
  • 打赏
  • 举报
回复
我有一个:

  Easay是一款插件式多功能局域网双机交流软件。局域网上两台运行本软件的计算机分别作为服务器和客户端进行联接,可实现即时聊天;打开插件后可实现更多实用功能。目前版本提供“网络五子棋”和“电子白板”插件,可实现网上对弈(人机/人人)和网上图形交流。


要的话联系:yumenlj@126.com 。给你聊天的源代码,不给插件的。
haoco 2005-03-06
  • 打赏
  • 举报
回复
up
qiezic 2005-03-06
  • 打赏
  • 举报
回复
关注
_-_-_-_- 2005-03-06
  • 打赏
  • 举报
回复
程序员杂志上有过一篇教怎样做的。。。可以去找找。。。很不错。。。
dangerousdon 2005-03-06
  • 打赏
  • 举报
回复
up
adun_ 2005-03-06
  • 打赏
  • 举报
回复
我的QQ是adun_@yeah.net,知道的也可以给我发电子邮件。。
adun_ 2005-03-06
  • 打赏
  • 举报
回复
顶一下,希望大家帮帮忙啊。我只写过一个 1对1的客户服务器模式的,我想写一个 1个服务器对多个客户的,请知道的帮帮我啊。谢谢了。
superghygf 2005-03-06
  • 打赏
  • 举报
回复
这个一般没有人愿意的,不妨我们合作一下可以还可能!
cfanwolf 2005-03-06
  • 打赏
  • 举报
回复
我做好了送你一个把,。要不我们一起研究把。。
godhand2 2005-03-05
  • 打赏
  • 举报
回复
mark up
zht1009 2005-03-05
  • 打赏
  • 举报
回复
关注!
grjs2004 2005-03-05
  • 打赏
  • 举报
回复
UP
hanyaocsdn 2005-03-05
  • 打赏
  • 举报
回复
mark
up
zyug 2005-03-05
  • 打赏
  • 举报
回复
up
wjcking 2005-03-05
  • 打赏
  • 举报
回复
//这里只有一个UDP的
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Net ;
using System.Net.Sockets ;
using System.Threading ;
//程序中使用到线程
using System.Text ;
namespace UDP聊天
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
 private System.Windows.Forms.Label label1 ;
 private System.Windows.Forms.ListBox listBox1 ;
 private System.Windows.Forms.TextBox textBox1 ;
 private System.Windows.Forms.Label label2 ;
 private System.Windows.Forms.Button button1 ;
 private System.Windows.Forms.Button button2 ;
 private System.Windows.Forms.TextBox textBox2 ;
 private System.Windows.Forms.Label label3 ;
 private System.Windows.Forms.StatusBar statusBar1 ;
 private bool ReadFlag = true ;
 //设定侦听标示位,通过它来设定是否侦听端口号
 private Thread th ;
 //定义一个线程,在线程接收聊天信息
 private IPEndPoint remote ;
 //定义一个远程结点,用以获取远程计算机IP地址和发送的聊天信息
 private UdpClient udpclient ;
 //创建一个UDP网络服务
 /// <summary>
 /// 必需的设计器变量。
 /// </summary>
 private System.ComponentModel.Container components = null ;

 public Form1 ( )
 {
  //
  // Windows 窗体设计器支持所必需的
  //
  InitializeComponent ( ) ;

  //
  // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  //
 }

 /// <summary>
 /// 清理所有正在使用的资源。
 /// </summary>
 protected override void Dispose ( bool disposing )
 {
  /*try
  {
  ReadFlag = false ;
  th.Abort ( ) ;
  remote =null ;
  udpclient.Close ( ) ;
  th = null ;
  }
  catch
  {}*/
  if ( disposing )
  {
  if ( components != null )
  {
   components.Dispose ( ) ;
  }
  }
  base.Dispose ( disposing ) ;
 }

 #region Windows Form Designer generated code
 /// <summary>
 /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 /// 此方法的内容。
 /// </summary>
 private void InitializeComponent ( )
 {
  this.label1 = new System.Windows.Forms.Label();
  this.listBox1 = new System.Windows.Forms.ListBox();
  this.textBox1 = new System.Windows.Forms.TextBox();
  this.label2 = new System.Windows.Forms.Label();
  this.button1 = new System.Windows.Forms.Button();
  this.button2 = new System.Windows.Forms.Button();
  this.textBox2 = new System.Windows.Forms.TextBox();
  this.label3 = new System.Windows.Forms.Label();
  this.statusBar1 = new System.Windows.Forms.StatusBar();
  this.SuspendLayout();
  //
  // label1
  //
  this.label1.Location = new System.Drawing.Point(11, 6);
  this.label1.Name = "label1";
  this.label1.Size = new System.Drawing.Size(91, 23);
  this.label1.TabIndex = 0;
  this.label1.Text = "接收信息:";
  //
  // listBox1
  //
  this.listBox1.Location = new System.Drawing.Point(9, 28);
  this.listBox1.Name = "listBox1";
  this.listBox1.Size = new System.Drawing.Size(318, 121);
  this.listBox1.TabIndex = 1;
  //
  // textBox1
  //
  this.textBox1.Location = new System.Drawing.Point(72, 200);
  this.textBox1.Name = "textBox1";
  this.textBox1.Size = new System.Drawing.Size(183, 20);
  this.textBox1.TabIndex = 3;
  this.textBox1.Text = "";
  //
  // label2
  //
  this.label2.Location = new System.Drawing.Point(26, 203);
  this.label2.Name = "label2";
  this.label2.Size = new System.Drawing.Size(91, 23);
  this.label2.TabIndex = 4;
  this.label2.Text = "信息:";
  //
  // button1
  //
  this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  this.button1.Location = new System.Drawing.Point(272, 200);
  this.button1.Name = "button1";
  this.button1.Size = new System.Drawing.Size(42, 28);
  this.button1.TabIndex = 5;
  this.button1.Text = "发送";
  this.button1.Click += new System.EventHandler(this.button1_Click);
  //
  // button2
  //
  this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  this.button2.Location = new System.Drawing.Point(272, 160);
  this.button2.Name = "button2";
  this.button2.Size = new System.Drawing.Size(42, 28);
  this.button2.TabIndex = 6;
  this.button2.Text = "接收";
  this.button2.Click += new System.EventHandler(this.button2_Click);
  //
  // textBox2
  //
  this.textBox2.Location = new System.Drawing.Point(73, 163);
  this.textBox2.Name = "textBox2";
  this.textBox2.Size = new System.Drawing.Size(181, 20);
  this.textBox2.TabIndex = 8;
  this.textBox2.Text = "";
  //
  // label3
  //
  this.label3.Location = new System.Drawing.Point(14, 164);
  this.label3.Name = "label3";
  this.label3.Size = new System.Drawing.Size(52, 23);
  this.label3.TabIndex = 7;
  this.label3.Text = "IP地址:";
  //
  // statusBar1
  //
  this.statusBar1.Location = new System.Drawing.Point(0, 251);
  this.statusBar1.Name = "statusBar1";
  this.statusBar1.Size = new System.Drawing.Size(337, 22);
  this.statusBar1.TabIndex = 9;
  this.statusBar1.Text = "程序不处于数据接收状态";
  //
  // Form1
  //
  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  this.ClientSize = new System.Drawing.Size(337, 273);
  this.Controls.AddRange(new System.Windows.Forms.Control[] {
          this.statusBar1,
          this.textBox2,
          this.label3,
          this.button2,
          this.button1,
          this.textBox1,
          this.listBox1,
          this.label2,
          this.label1});
  this.MaximizeBox = false;
  this.Name = "Form1";
  this.Text = "UDP聊天";
  this.ResumeLayout(false);

 }
 #endregion

 /// <summary>
 /// 应用程序的主入口点。
 /// </summary>
 [STAThread]
 static void Main ( )
 {
  Application.Run ( new Form1 ( ) ) ;
 }
 private void read ( )
 {
  //侦听本地的8000端口号
  udpclient = new UdpClient ( 8000 ) ;
  remote = null ;
  //设定编码类型
  Encoding enc = Encoding.Unicode ;
  while ( ReadFlag == true )
  {
  Byte[] data = udpclient.Receive ( ref remote ) ;
  //得到对方发送来的聊天信息
  String strData = enc.GetString ( data ) ;
  //获取传送信息到本地端口号的远程计算机IP地址
  string remoteIP = remote.Address.ToString ( ) ;
  //显示接收信息以及传送信息的计算机IP地址
  listBox1.Items.Add ( remoteIP + ":" + strData ) ;
  }
 }
 private void button1_Click ( object sender , System.EventArgs e )
 {
  //创建UDP网络服务
  UdpClient SendUdp = new UdpClient ( ) ;
  IPAddress remoteIP ;
  //判断IP地址的正确性
  try
  {
  remoteIP = IPAddress.Parse ( textBox2.Text );
  }
  catch
  {
  MessageBox.Show ( "请输入正确的IP地址!" , "错误" ) ;
  return ;
  }
  IPEndPoint remoteep = new IPEndPoint ( remoteIP , 8000 ) ;
  Byte [] buffer = null ;
  Encoding enc = Encoding.Unicode ;
  string str = textBox1.Text ;
  buffer = enc.GetBytes ( str.ToCharArray ( ) ) ;
  //传送信息到指定计算机的8000端口号
  SendUdp.Send ( buffer , buffer.Length , remoteep ) ;
  textBox1.Clear ( ) ;
  //关闭UDP网络服务
  SendUdp.Close ( ) ;
 }


 private void button2_Click ( object sender , System.EventArgs e )
 {
  //创建一个线程
  th = new Thread ( new ThreadStart ( read ) ) ;
  //启动线程
  th.Start ( ) ;
  statusBar1.Text ="程序处于数据接收状态!" ;
 }
}
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧