本文整理匯總了VB.NET中System.Net.Sockets.TcpListener.AcceptSocket方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET TcpListener.AcceptSocket方法的具體用法?VB.NET TcpListener.AcceptSocket怎麽用?VB.NET TcpListener.AcceptSocket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.Sockets.TcpListener
的用法示例。
在下文中一共展示了TcpListener.AcceptSocket方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1:
' Accepts the pending client connection and returns a socket for communciation.
Dim socket As Socket = tcpListener.AcceptSocket()
Console.WriteLine("Connection accepted.")
Dim responseString As String = "You have successfully connected to me"
'Forms and sends a response string to the connected client.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString)
Dim i As Integer = socket.Send(sendBytes)
Console.WriteLine(("Message Sent /> : " + responseString))
示例2: TcpListener.AcceptSocket()
' 導入命名空間
Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Imports System.Text
Public Class Tester
Dim Shared myTcpListener As TcpListener
Public Shared Sub Main
Dim myThread As New Thread(New ThreadStart(AddressOf StartListen))
myThread.Start()
End Sub
Private Shared Sub StartListen()
myTcpListener = New TcpListener(12334)
Dim blnConection As Boolean = False
Try
myTcpListener.Start()
Dim mySocket As Socket = myTcpListener.AcceptSocket()
Do
If mySocket.Connected = True Then blnConection = True
Loop Until blnConection = True
myTcpListener.Stop()
Catch ex As SocketException
Console.WriteLine(ex.Message)
End Try
End Sub
End Class