今天自己做了一个小软件,取名叫FreeChat
主要的用途是局域网内聊天,主要用到.net 的Socket类.Thread并自己封装了数据包.
下载地址:/Files/BearOcean/FreeChat(Beta).rar
现在作为Beta版发布...也把源代码发出来.我是菜鸟.希望高手不要鄙视.因为是基于.net的,所以至少需要FrameWork1.1
使用说明如下图:
很简单...在1.0中想添加一些其他的功能.比如允许文件传送,而且觉得输入IP或者计算机名的方式有点麻烦.
原代码如下:
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.Text;
using System.IO;
using System.Threading;
namespace FreeChat
{
public class FmFreeChat : System.Windows.Forms.Form
{
const int MSGINFOLENGTH=10;
const int MSGREMOTENAME=20;
const int MAXPACKSIZE=100;
private System.Windows.Forms.Button BtSend;
private System.Windows.Forms.Button BtExit;
private System.Windows.Forms.RichTextBox RtxSend;
private System.Windows.Forms.RichTextBox RtxInfo;
private System.Windows.Forms.Label LbComName;
private System.Windows.Forms.TextBox TxtTarget;
private IPHostEntry hostentryHost;
private IPEndPoint endpointHost;
private Socket sockListener;
private Thread thWorker;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MainMenu MeunFreeChat;
private System.Windows.Forms.MenuItem menuItemSave;
private System.Windows.Forms.MenuItem menuItemSaveClear;
private System.Windows.Forms.MenuItem menuItemClear;
private System.Windows.Forms.MenuItem menuItemHelp;
private System.Windows.Forms.MenuItem menuItemAbFreeChat;
private System.Windows.Forms.MenuItem menuItemAbMe;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.ComponentModel.Container components = null;
public FmFreeChat()
{
InitializeComponent();
}
Dispose#region Dispose
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
if(sockListener!=null)
{
sockListener.Close();
}
}
base.Dispose( disposing );
}
#endregion
Windows#region Windows
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FmFreeChat));
this.RtxInfo = new System.Windows.Forms.RichTextBox();
this.TxtTarget = new System.Windows.Forms.TextBox();
this.LbComName = new System.Windows.Forms.Label();
this.RtxSend = new System.Windows.Forms.RichTextBox();
this.BtSend = new System.Windows.Forms.Button();
this.BtExit = new System.Windows.Forms.Button();
this.MeunFreeChat = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItemSave = new System.Windows.Forms.MenuItem();
this.menuItemSaveClear = new System.Windows.Forms.MenuItem();
this.menuItemClear = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItemHelp = new System.Windows.Forms.MenuItem();
this.menuItemAbFreeChat = new System.Windows.Forms.MenuItem();
this.menuItemAbMe = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// RtxInfo
//
this.RtxInfo.AutoWordSelection = true;
this.RtxInfo.BackColor = System.Drawing.SystemColors.Info;
this.RtxInfo.Location = new System.Drawing.Point(10, 40);
this.RtxInfo.Name = "RtxInfo";
this.RtxInfo.ReadOnly = true;
this.RtxInfo.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.RtxInfo.Size = new System.Drawing.Size(320, 112);
this.RtxInfo.TabIndex = 0;
this.RtxInfo.Text = "";
this.RtxInfo.TextChanged += new System.EventHandler(this.RtxInfo_TextChanged);
//
// TxtTarget
//
this.TxtTarget.Location = new System.Drawing.Point(58, 9);
this.TxtTarget.Name = "TxtTarget";
this.TxtTarget.Size = new System.Drawing.Size(134, 21);
this.TxtTarget.TabIndex = 1;
this.TxtTarget.Text = "";
//
// LbComName
//
this.LbComName.Location = new System.Drawing.Point(0, 9);
this.LbComName.Name = "LbComName";
this.LbComName.Size = new System.Drawing.Size(58, 19);
this.LbComName.TabIndex = 2;
this.LbComName.Text = "Target:";
this.LbComName.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// RtxSend
//
this.RtxSend.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.RtxSend.Location = new System.Drawing.Point(10, 160);
this.RtxSend.Name = "RtxSend";
this.RtxSend.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.RtxSend.Size = new System.Drawing.Size(320, 88);
this.RtxSend.TabIndex = 3;
this.RtxSend.Text = "";
//
// BtSend
//
this.BtSend.Location = new System.Drawing.Point(10, 256);
this.BtSend.Name = "BtSend";
this.BtSend.Size = new System.Drawing.Size(90, 27);
this.BtSend.TabIndex = 4;
this.BtSend.Text = "Send";
this.BtSend.Click += new System.EventHandler(this.BtSend_Click);
//
// BtExit
//
this.BtExit.Location = new System.Drawing.Point(134, 256);
this.BtExit.Name = "BtExit";
this.BtExit.Size = new System.Drawing.Size(90, 27);
this.BtExit.TabIndex = 5;
this.BtExit.Text = "Exit";
this.BtExit.Click += new System.EventHandler(this.BtExit_Click);
//
// MeunFreeChat
//
this.MeunFreeChat.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItemHelp});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemSave,
this.menuItemSaveClear,
this.menuItemClear,
this.menuItem6});
this.menuItem1.Text = "Record";
//
// menuItemSave
//
this.menuItemSave.Index = 0;
this.menuItemSave.Text = "Save";
this.menuItemSave.Click += new System.EventHandler(this.menuItemSave_Click);
//
// menuItemSaveClear
//
this.menuItemSaveClear.Index = 1;
this.menuItemSaveClear.Text = "SaveClear";
this.menuItemSaveClear.Click += new System.EventHandler(this.menuItemSaveClear_Click);
//
// menuItemClear
//
this.menuItemClear.Index = 2;
this.menuItemClear.Text = "Clear";
this.menuItemClear.Click += new System.EventHandler(this.menuItemClear_Click);
//
// menuItem6
//
this.menuItem6.Index = 3;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7,
this.menuItem8});
this.menuItem6.Text = "AutoSave";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "ON";
//
// menuItem8
//
this.menuItem8.Checked = true;
this.menuItem8.Index = 1;
this.menuItem8.Text = "OFF";
//
// menuItemHelp
//
this.menuItemHelp.Index = 1
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.Text;
using System.IO;
using System.Threading;
namespace FreeChat
{
public class FmFreeChat : System.Windows.Forms.Form
{
const int MSGINFOLENGTH=10;
const int MSGREMOTENAME=20;
const int MAXPACKSIZE=100;
private System.Windows.Forms.Button BtSend;
private System.Windows.Forms.Button BtExit;
private System.Windows.Forms.RichTextBox RtxSend;
private System.Windows.Forms.RichTextBox RtxInfo;
private System.Windows.Forms.Label LbComName;
private System.Windows.Forms.TextBox TxtTarget;
private IPHostEntry hostentryHost;
private IPEndPoint endpointHost;
private Socket sockListener;
private Thread thWorker;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MainMenu MeunFreeChat;
private System.Windows.Forms.MenuItem menuItemSave;
private System.Windows.Forms.MenuItem menuItemSaveClear;
private System.Windows.Forms.MenuItem menuItemClear;
private System.Windows.Forms.MenuItem menuItemHelp;
private System.Windows.Forms.MenuItem menuItemAbFreeChat;
private System.Windows.Forms.MenuItem menuItemAbMe;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.ComponentModel.Container components = null;
public FmFreeChat()
{
InitializeComponent();
}
Dispose#region Dispose
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
if(sockListener!=null)
{
sockListener.Close();
}
}
base.Dispose( disposing );
}
#endregion
Windows#region Windows
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FmFreeChat));
this.RtxInfo = new System.Windows.Forms.RichTextBox();
this.TxtTarget = new System.Windows.Forms.TextBox();
this.LbComName = new System.Windows.Forms.Label();
this.RtxSend = new System.Windows.Forms.RichTextBox();
this.BtSend = new System.Windows.Forms.Button();
this.BtExit = new System.Windows.Forms.Button();
this.MeunFreeChat = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItemSave = new System.Windows.Forms.MenuItem();
this.menuItemSaveClear = new System.Windows.Forms.MenuItem();
this.menuItemClear = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItemHelp = new System.Windows.Forms.MenuItem();
this.menuItemAbFreeChat = new System.Windows.Forms.MenuItem();
this.menuItemAbMe = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// RtxInfo
//
this.RtxInfo.AutoWordSelection = true;
this.RtxInfo.BackColor = System.Drawing.SystemColors.Info;
this.RtxInfo.Location = new System.Drawing.Point(10, 40);
this.RtxInfo.Name = "RtxInfo";
this.RtxInfo.ReadOnly = true;
this.RtxInfo.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.RtxInfo.Size = new System.Drawing.Size(320, 112);
this.RtxInfo.TabIndex = 0;
this.RtxInfo.Text = "";
this.RtxInfo.TextChanged += new System.EventHandler(this.RtxInfo_TextChanged);
//
// TxtTarget
//
this.TxtTarget.Location = new System.Drawing.Point(58, 9);
this.TxtTarget.Name = "TxtTarget";
this.TxtTarget.Size = new System.Drawing.Size(134, 21);
this.TxtTarget.TabIndex = 1;
this.TxtTarget.Text = "";
//
// LbComName
//
this.LbComName.Location = new System.Drawing.Point(0, 9);
this.LbComName.Name = "LbComName";
this.LbComName.Size = new System.Drawing.Size(58, 19);
this.LbComName.TabIndex = 2;
this.LbComName.Text = "Target:";
this.LbComName.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// RtxSend
//
this.RtxSend.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.RtxSend.Location = new System.Drawing.Point(10, 160);
this.RtxSend.Name = "RtxSend";
this.RtxSend.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.RtxSend.Size = new System.Drawing.Size(320, 88);
this.RtxSend.TabIndex = 3;
this.RtxSend.Text = "";
//
// BtSend
//
this.BtSend.Location = new System.Drawing.Point(10, 256);
this.BtSend.Name = "BtSend";
this.BtSend.Size = new System.Drawing.Size(90, 27);
this.BtSend.TabIndex = 4;
this.BtSend.Text = "Send";
this.BtSend.Click += new System.EventHandler(this.BtSend_Click);
//
// BtExit
//
this.BtExit.Location = new System.Drawing.Point(134, 256);
this.BtExit.Name = "BtExit";
this.BtExit.Size = new System.Drawing.Size(90, 27);
this.BtExit.TabIndex = 5;
this.BtExit.Text = "Exit";
this.BtExit.Click += new System.EventHandler(this.BtExit_Click);
//
// MeunFreeChat
//
this.MeunFreeChat.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItemHelp});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemSave,
this.menuItemSaveClear,
this.menuItemClear,
this.menuItem6});
this.menuItem1.Text = "Record";
//
// menuItemSave
//
this.menuItemSave.Index = 0;
this.menuItemSave.Text = "Save";
this.menuItemSave.Click += new System.EventHandler(this.menuItemSave_Click);
//
// menuItemSaveClear
//
this.menuItemSaveClear.Index = 1;
this.menuItemSaveClear.Text = "SaveClear";
this.menuItemSaveClear.Click += new System.EventHandler(this.menuItemSaveClear_Click);
//
// menuItemClear
//
this.menuItemClear.Index = 2;
this.menuItemClear.Text = "Clear";
this.menuItemClear.Click += new System.EventHandler(this.menuItemClear_Click);
//
// menuItem6
//
this.menuItem6.Index = 3;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7,
this.menuItem8});
this.menuItem6.Text = "AutoSave";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "ON";
//
// menuItem8
//
this.menuItem8.Checked = true;
this.menuItem8.Index = 1;
this.menuItem8.Text = "OFF";
//
// menuItemHelp
//
this.menuItemHelp.Index = 1