• 大小: 335KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-02-08
  • 语言: C#
  • 标签: .net  五子棋  聊天室  

资源简介

.net 编写五子棋 双人局域对战网通信 聊天室,VS2010源码,可运行

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Text.Regularexpressions;


namespace 五子棋
{
    public partial class Chat : Form
    {
        public Chat()
        {
            
            InitializeComponent();
            listBoxCallback = new AddListBoxItemCallback(AddListBoxItem);
        }
        delegate void AddListBoxItemCallback(string text);
        AddListBoxItemCallback listBoxCallback;
        private int port = 8001;
        private UdpClient udpClient;


        private void Chat_Load(object sender EventArgs e)
        {

            listBoxReceive.HorizontalScrollbar = true;
            listBoxReceive.Dock = Dockstyle.Fill;
            IPAddress myIP = (IPAddress)Dns.GetHostAddresses(Dns.GetHostName()).GetValue(0);
            textBoxRemoteIP.Text = myIP.ToString();
            Thread myThread = new Thread(new ThreadStart(ReceiveData));
            myThread.IsBackground = true;
            myThread.Start();
            textBoxSend.Focus();
            
        }

        private void buttonSend_Click(object sender EventArgs e)
        {
            sendData();
        }
        private void sendData()
        {

            UdpClient myUdpClient = new UdpClient();
            IPAddress remoteIP;
            if (IPAddress.TryParse(textBoxRemoteIP.Text out remoteIP) == false)
            {
                MessageBox.Show(“远程IP格式不正确“);
                return;
            }
            IPEndPoint iep = new IPEndPoint(remoteIP port);
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(textBoxSend.Text);
            try
            {
                string data = null;
                myUdpClient.Send(bytes bytes.Length iep);
                data = textBoxSend.Text;
                AddListBoxItem(string.Format(“来自我的:{0}“ data));
                textBoxSend.Clear();
                myUdpClient.Close();
                textBoxSend.Focus();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message “发送失败“);
            }
            finally
            {
                myUdpClient.Close();
            }
        }
        private void AddListBoxItem(string text)
        {
            if (listBoxReceive.InvokeRequired)
            {
                this.Invoke(listBoxCallback text);
            }
            else
            {
                listBoxReceive.Items.Add(text);
                listBoxReceive.SelectedIndex = listBoxReceive.Items.Count - 1;
            }
        }

        private void ReceiveData()
        {
            udpClient = new UdpClient(port);
            IPEndPoint remote = null;
            while (true)
            {
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        869  2014-06-24 09:50  五子棋\五子棋.sln

    ..A..H.     29696  2014-06-27 10:42  五子棋\五子棋.suo

    ..A..H.     38912  2016-07-25 19:56  五子棋\五子棋.v11.suo

     文件       3583  2014-06-27 10:42  五子棋\五子棋\Chat.cs

     文件       5779  2014-06-27 10:42  五子棋\五子棋\Chat.Designer.cs

     文件       5817  2014-06-27 10:42  五子棋\五子棋\Chat.resx

     文件       2269  2014-06-27 10:42  五子棋\五子棋\Friend.cs

     文件       3630  2014-06-27 10:42  五子棋\五子棋\Friend.Designer.cs

     文件       5817  2014-06-27 10:42  五子棋\五子棋\Friend.resx

     文件        492  2014-06-24 10:18  五子棋\五子棋\FriendInfo.cs

     文件      33031  2014-06-25 11:41  五子棋\五子棋\MainForm1.cs

     文件       7892  2014-06-25 11:01  五子棋\五子棋\MainForm1.Designer.cs

     文件       6015  2014-06-25 11:01  五子棋\五子棋\MainForm1.resx

     文件        386  2014-06-24 10:25  五子棋\五子棋\MsgType.cs

     文件        494  2014-06-24 10:08  五子棋\五子棋\Program.cs

     文件       4421  2014-06-25 11:31  五子棋\五子棋\五子棋.csproj

     文件      89600  2014-06-27 10:33  五子棋\五子棋\bin\Debug\五子棋.exe

     文件      65024  2014-06-27 10:33  五子棋\五子棋\bin\Debug\五子棋.pdb

     文件      22984  2016-07-25 19:56  五子棋\五子棋\bin\Debug\五子棋.vshost.exe

     文件        490  2012-06-06 02:06  五子棋\五子棋\bin\Debug\五子棋.vshost.exe.manifest

     文件       4440  2014-06-24 15:02  五子棋\五子棋\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7071  2016-07-25 19:56  五子棋\五子棋\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       6390  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\GenerateResource.read.1.tlog

     文件       7082  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\GenerateResource.write.1.tlog

     文件        180  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\五子棋.Chat.resources

     文件       6679  2016-07-25 19:56  五子棋\五子棋\obj\x86\Debug\五子棋.csproj.FileListAbsolute.txt

     文件      89600  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\五子棋.exe

     文件        180  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\五子棋.Friend.resources

     文件      65024  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\五子棋.pdb

     文件      63352  2014-06-27 10:33  五子棋\五子棋\obj\x86\Debug\五子棋.Properties.Resources.resources

............此处省略24个文件信息

评论

共有 条评论