-
VB.NET通过Socket实现字符串发送与接收程序
1
2
3
4
5
|
Imports System.Net.sockets Imports System.net Imports System.Text Imports System.Threading 定义两个窗体变量 |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Public Sub WaitData() s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)'''使用TCP协议 Dim localEndPoint As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 1024) '''指定IP和Port s.Bind(localEndPoint) '''绑定到该Socket s.Listen(100) '''侦听,最多接受100个连接 While (True) Dim bytes(1024) As Byte '''用来存储接收到的字节 Dim ss As Socket = s.Accept() '''若接收到,则创建一个新的Socket与之连接 ss.Receive(bytes) '''接收数据,若用ss.send(Byte()),则发送数据 ListBox1.Items.Insert(0, Encoding.Unicode.GetString(bytes))'''将其插入到列表框的第一项之前 '''若使用Encoding.ASCII.GetString(bytes),则接收到的中文字符不能正常显示 End While End Sub |
1
2
3
4
5
6
7
8
9
10
11
|
t = New Thread(AddressOf WaitData) '''建立新的线程 t.Start() '''启动线程 BtnStart.Enabled = False '''按钮不可用,避免另启线程 在BtnStop的click事件中,加入如下代码: Try s.Close() '''关闭Socket t.Abort() '''中止线程 Catch Finally BtnStart.Enabled = True '''启用BtnStart End Try |
1
2
3
4
5
|
Try s.Close() t.Abort() Catch End Try |
1
2
3
4
5
6
7
8
9
|
Try Dim bytes(1024) As Byte Dim s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim localEndPoint As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 1024) s.Connect(localEndPoint) s.Send(Encoding.Unicode.GetBytes(TextBox1.Text)) s.Close() Catch ex As Exception End Try |
栏目列表
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比