End Sub
'建立连连接
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ipremote As IPAddress
Dim tcpclient As TcpClient
Try
ipremote = IPAddress.Parse(Me.TextBox1.Text)
Catch ex As Exception
MessageBox.Show("IP地址不合法vb.nettcp连接!", "错误提示")
End Try
Try
tcpclient = New TcpClient(Me.TextBox1.Text, 8000)
ns = tcpclient.GetStream
swriter = New StreamWriter(ns)
Me.StatusBar1.Text = "已经连接上"
Me.Button2.Enabled = False
Me.Button1.Enabled = True
tcpconnected = True
Catch ex As Exception
MessageBox.Show("无法与远程8000端口建立连接vb.nettcp连接!", "错误提示")
End Try
End Sub
Private Sub listen()
Try
Dim tcplistener As New TcpListener(IPAddress.Parse("127.0.0.1"), 8000)
tcplistener.Start()
tcpclient = tcplistener.AcceptTcpClient
ns = tcpclient.GetStream()
nsread = New StreamReader(ns)
While True
Dim msg As String = nsread.ReadLine
If msg = "stop" Then
tcplistener.Stop()
ns.Close()
nsread.Close()
mythread.Abort()
Else
Dim mytime As String = DateTime.Now.ToShortTimeString
Me.ListBox1.Items.Add(mytime + "" + msg)
End If
End While
Catch ex As System.Security.SecurityException
MessageBox.Show("侦听失败!", "错误")
End Try
End Sub
End Class
【vb.nettcp连接 vbnet socket】关于vb.nettcp连接和vbnet socket的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 电脑群直播签到怎么签,直播签到表怎么做
- sqlserver数据库文件夹,sqlserver 数据文件
- 鸿蒙桌面创意布局加文字,鸿蒙桌面创意布局加文字怎么弄
- 开直播要具备什么工具,开直播要具备什么工具和技术
- php升级数据库 php数据库更新语句
- 智慧电视连接功放机怎么连,智能电视怎样连接功放机
- 便宜的国外服务器推荐吗,国外服务器买哪个好用
- 新联想电脑怎么换系统,联想电脑更换系统设置
- 字符串函数在c语言中 c语言字符串函数用法