그래서 sendto() 함수를 사용하여 클라이언트에 메시지를 보내려고합니다.sendto() 함수에서 구조체 보내기 - C 언어
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
하지만 두 번째 인수로 구조를 보내고 싶습니다 :
sendto를() 함수의 프로토 타입이있다. 내가 그 일을 할 수 있니? 아니면 buf가 문자열이어야합니까?
편집 : 당신이보고, 나는이를 보낼 수 있어야합니다 :
PAYLOAD ""다음에 "HEADER"메시지가 구성 "
귀하의 메시지 헤더는 다음과 같이 구성해야합니다.
uint8_t version; /* must be 1. If you receive anything else, discard*/
uint8_t ttl; /* must be 1. If you receive anything else, discard*/
uint16_t payload_length; /* bytes following the header */
uint32_t account_identifier; /* digits of your account name */
uint32_t source_address; /* unused for now, set to 0 and ignore. */
uint32_t destination_address; /* unused for now, set to 0 and ignore. */
uint16_t checksum; /* unused for now, set to 0 and ignore. */
uint16_t protocol; /* must be 1. If you receive anything else, discard*/"
그리고 페이로드 텍스트 "안녕하세요"와 같은 문자열이나 뭔가를합니다. 나는 모든의 구조체를 보낼 날이 될 것 헤더를 보낼 수있는 유일한 방법 같은 느낌
그 정보. 권리?
예, 상호 운용성은 문제가되지 않습니다. 서버의 하드웨어는 동일합니다. – umdcoder
보낼 수 있도록 포인터가있는 구조체가 있습니까? – umdcoder
@umdcoder 아니야. 일반적으로 구조체를 보내는 것은 좋지 않습니다. 구조체를 네트워크 프로토콜로 사용하지 마십시오. 네트워크 프로토콜을 네트워크 프로토콜로 사용하십시오. – EJP