VB.Net by API/System.Net.Sockets/TcpListener

Материал из VB Эксперт
Версия от 12:50, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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


TcpListener.Start()

  
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