基于.NET Framework的局域网通信(socket尝试)

之前写的一个基于.NET Framework的局域网通信的软件,有些bug,不过只是为了探究一下socket通信,后续技术熟练以后会对它进行二次迭代,最开始做了一个基于控制台的,后面想了一下,还是需要用可视化界面,所以选择了.NET Framework框架又实现了一遍,也遇到了一些新的问题,最终实现了基本的聊天的发送和接收功能,通信类如下:

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

namespace Communication_software_windows
{
    class Sockt_communication
    {
        public string user_name = "default";
        public string _ip = string.Empty;
        private string _ip1 = string.Empty;
        private int _port = 0;
        private int port1 = 0;
        public Socket _socket = null;
        public Socket _socket1 = null;
        private byte[] buffer = new byte[1024 * 1024 * 2];
        private byte[] buffer1 = new byte[1024 * 1024 * 2];
        private IPAddress address;
        private IPEndPoint endPoint;
        public TextBox receive_box;
        public TextBox sendmessage_box;
        delegate void UpdateUIDelegate(string text);

        void UpdateUI(string text)
        {
            receive_box.Text += text;
        }

        //无参构造函数
        public Sockt_communication()
        {

        }

        public Sockt_communication(string ip, string ip1, int port, int port1, string user_name)
        {
            this._ip = ip;
            this._ip1 = ip1;
            this._port = port;
            this.port1 = port1;
            this.user_name = user_name;
      
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值