TcpListener.AcceptSocket 메서드

정의

보류 중인 연결 요청을 받아들입니다.

public:
 System::Net::Sockets::Socket ^ AcceptSocket();
public System.Net.Sockets.Socket AcceptSocket ();
member this.AcceptSocket : unit -> System.Net.Sockets.Socket
Public Function AcceptSocket () As Socket

반환

데이터를 보내고 받는 데 사용되는 Socket입니다.

예외

Start()의 호출과 함께 수신기가 시작하지 않은 경우

예제

다음 코드 예제에서 메서드는 AcceptSocket 를 반환 Socket하는 데 사용됩니다. 새로 Socket 연결된 클라이언트와 통신하는 데 사용됩니다.

// Accepts the pending client connection and returns a socket for communciation.
Socket^ socket = tcpListener->AcceptSocket();
Console::WriteLine( "Connection accepted." );

String^ responseString = "You have successfully connected to me";

//Forms and sends a response string to the connected client.
array<Byte>^sendBytes = Encoding::ASCII->GetBytes( responseString );
int i = socket->Send( sendBytes );
Console::WriteLine( "Message Sent /> : {0}", responseString );

          // Accepts the pending client connection and returns a socket for communication.
           Socket socket = tcpListener.AcceptSocket();
            Console.WriteLine("Connection accepted.");

           string responseString = "You have successfully connected to me";

           //Forms and sends a response string to the connected client.
           Byte[] sendBytes = Encoding.ASCII.GetBytes(responseString);
           int i = socket.Send(sendBytes);
           Console.WriteLine("Message Sent /> : " + responseString);
' 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))

설명

AcceptSocket 는 데이터를 보내고 받는 데 사용할 수 있는 을 Socket 반환하는 차단 메서드입니다. 차단을 방지하려면 메서드를 Pending 사용하여 들어오는 연결 큐에서 연결 요청을 사용할 수 있는지 확인합니다.

반환된 는 Socket 원격 호스트의 IP 주소 및 포트 번호로 초기화됩니다. 클래스에서 Send 사용할 수 있는 및 Receive 메서드를 Socket 사용하여 원격 호스트와 통신할 수 있습니다. 사용을 마치면 메서드를 Socket호출 Close 해야 합니다. 애플리케이션이 비교적 단순한 경우 사용을 고려 합니다 AcceptTcpClient 메서드 대신 AcceptSocket 메서드. TcpClient 는 동기 모드 차단에서 네트워크를 통해 데이터를 보내고 받는 간단한 방법을 제공합니다.

참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

적용 대상

추가 정보