Monday, June 23, 2008

UDP

UDP는 별도의 연결 과정이 없다. 때문에 매번 보낼때 송수신 주소를 담아서 보내고 받는다. 그리고 broadcast, multicast 식으로 한번에 여러 곳으로 데이터를 송신할 수 있다. 일단 bind()로 바인딩 후 sendto(), recvfrom()으로 주고 받는다. 송수신이 완료되면 close(), shutdown()으로 소켓을 닫는다. 연결이 없어서 server, client 구분이 없다. 간단하다.

int sendto (int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);

인자는, 뭐 대충,.. 소켓, 데이터, 데이터길이, 옵션, 송(수)신 주소, 주소 길이.. 식이다.

No comments:

Post a Comment