vb.nettcp连接 vbnet socket( 二 )


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的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

推荐阅读