以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]求助:Socket 客户端连接服务端 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=184913) |
-- 作者:machle -- 发布时间:2023/1/15 12:03:00 -- [求助]求助:Socket 客户端连接服务端 Socket 客户端连接服务端,没问题。问题:当通讯一方中断,会出现闪退和死掉不动的情况。下面代码是启动监听的界面,请问我该如何新建一个ServerSocket? 能否给我一个完整代码,找了很长时间,每个帖子都是解决某一个问题,但又会带来新的问题,拼凑在一起也不行。个人能力确实不太够。谢谢!!
Dim lab1 As WinForm.Label = e.Form.Controls("Label1") \'Dim ServerSocket As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) Dim listener As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) Dim localEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.1.131"), 8080) If ServerSocket Is Nothing Then Dim ServerSocket As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) End If \'If listener.Close Is True Then \' listener. \'End If If Vars("lianjie") = False Then ServerThread = New System.Threading.Thread(AddressOf Listen) ServerThread.Start() lab1.Text = "监听装态:" & "已经开始监听8080端口" Else lab1.Text = "监听装态:" & "已经开始监听8080端口" End If |
-- 作者:有点蓝 -- 发布时间:2023/1/15 20:38:00 -- 请上传实例测试 |