VB.NET中TCP通讯代码(客户端和接受端集成在一个窗口中)

这篇博客展示了如何在VB.NET中创建一个集成了客户端和服务器端的TCP通信程序。通过Designer.vb文件定义了用户界面,包括文本框、按钮等组件,用于输入服务器地址、信息和进行连接、发送操作。程序使用TcpListener和TcpClient类进行TCP连接,通过线程监听端口并接收、发送数据。当接收到特定控制码时,会关闭连接并更新界面状态。
摘要由CSDN通过智能技术生成
      
        1、首先是界面的设置,界面设置系统会自动在Designer.vb这个文件中记录下来 ,下面是该文件的代码:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
       Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.BtnLink = New System.Windows.Forms.Button
        Me.BtnSend = New System.Windows.Forms.Button
        Me.LabService = New System.Windows.Forms.Label
        Me.ListBoxClientContext = New System.Windows.Forms.ListBox
        Me.StartService = New System.Windows.Forms.Button
        Me.StatusStrip1 = New System.Windows.Forms.StatusStrip
        Me.ToolStripLable1 = New System.Windows.Forms.ToolStripStatusLabel
        Me.ToolStripSeviceStatus = New System.Windows.Forms.ToolStripStatusLabel
        Me.StatusStrip1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(25, 22)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(77, 12)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "服务器地址:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(25, 69)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(41, 12)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "信息:"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(115, 19)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(149, 21)
        Me.TextBox1.TabIndex = 2
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(115, 69)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(149, 21)
        Me.TextBox2.TabIndex = 3
        '
        'BtnLink
        '
        Me.BtnLink.Location = New System.Drawing.Point(27, 130)
        Me.BtnLink.Name = "BtnLink"
        Me.BtnLink.Size = New System.Drawing.Size(75, 23)
        Me
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值