zoukankan      html  css  js  c++  java
  • 内网聊天工具FreeChat Beta

    今天自己做了一个小软件,取名叫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

            
    Windows
            
            [STAThread]

            
    Main

            
    FreeChatInit

            
    WorkerProc

            
    FmFreeChat_Load

            
    BtExit_Click

            
    BtSend_Click

            
    RtxInfo_TextChanged

            
    menuItemClear

            
    RecordSave

            
    menuItemSave

            
    menuItemSaveClear

            
    menuItemAbFreeChat

            
    menuItemAbMe

            
            
        }

    }

    然后是负责储存聊天记录的部分:

     

    using System;
    using System.Windows.Forms;
    using System.IO;

    namespace FreeChat
    {
        
    /// <summary>
        
    /// Record 
        
    /// </summary>

        public class Record
        
    {
            
    public Record()
            
    {
                
            }


            
    public static void RecordMessage(string strMessage)//CreateDirectory And File
            {
                Directory.CreateDirectory(
    "FreeChatLogs");
                DateTime dt
    =DateTime.Now;
                
    string today=dt.ToString("yyyy-MM-dd");
                
    string strRecordTime=dt.ToString("yyyy-MM-dd:HH:mm:ff");

                StreamWriter swRecordFile
    =new StreamWriter(String.Concat("FreeChatLogs\\",today,".chat"),true,System.Text.Encoding.UTF8);
                swRecordFile.WriteLine(String.Concat(
    "RecordTime:",strRecordTime));
                swRecordFile.WriteLine(
    "------------------------------------------------------------------");
                swRecordFile.Write(strMessage);
                swRecordFile.Write(
    "\n\n\n\n\n");
                swRecordFile.Close();

                MessageBox.Show(
    "Record Success","FreeChat");
                
            }

        }

    }


    代码基本上就是这些.1.0肯定会对它进行补全和修改,还有功能添加.

     

  • 相关阅读:
    不容易系列之(3)—— LELE的RPG难题(递推)
    亲和数(因子和)
    爬虫正式学习day2
    爬虫小练习:堆糖图片抓取--爬虫正式学习day1
    js笔记--高阶函数array的各种函数
    js笔记--高阶函数sort()
    js笔记--高阶函数filter()
    js笔记--高阶函数map() reduce()
    js笔记--方法
    js笔记--变量部分
  • 原文地址:https://www.cnblogs.com/BearOcean/p/319310.html
Copyright © 2011-2022 走看看