컴퓨터/C#

C# TCP Client (소켓 사용)

Begi 2022. 10. 4. 23:31
반응형

소켓을 이용한 TCP Client 프로그램은 다음과 같다.

 

            // 소켓 생성
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
            // 서버 연결
            var p = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 500);
            sock.Connect(p);
 

            // 데이타 전송

            byte[] buf = new byte[1024];
            sock.Send(buff, SocketFlags.None);
 
            // 데이타 수신
            int n = sock.Receive(buf);
 
            // 소켓 닫기
            sock.Close();

 

 TCP Server (TcpClient 사용)

 TCP Client (TcpClient 사용)

 TCP Server (소켓 사용)

 TCP Client (소켓 사용)

 

 

 

반응형