본문 바로가기

프로그래밍 _공부자료./C++ 공부46

c++ 데이타송수신 #include // std::byte를 위한 헤더 #include #include // std::unique_ptr를 위한 헤더 #include // std::memcpy를 위한 헤더 int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... int header_length = 100; // 헤더의 길이 std::unique_ptr header(new std::byte[header_length]); // 헤더를 저장할 동적 배열 while (true) { ssize_t n = recv(sockfd, header.get(), header_length, 0); // 헤더 받기 if (n == -1) { // 에러 처리 코드... } int body_len.. 2023. 11. 13.
c++ soket통신 receive header와 body #include #include // std::byte를 위한 헤더 #include #include // std::copy를 위한 헤더 int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... int header_length = 100; // 헤더의 길이 std::vector header(header_length); // 헤더를 저장할 동적 배열 while (true) { ssize_t n = recv(sockfd, header.data(), header.size(), 0); // 헤더 받기 if (n == -1) { // 에러 처리 코드... } header.resize(n); // 실제로 받은 데이터만큼 크기 조정 int body_length = .. 2023. 11. 10.
std::byte 동적으로 메시지 수신받기 #include #include // std::byte를 위한 헤더 #include int main() { int sockfd; // 소켓 파일 디스크립터 // sockfd 초기화하는 코드... std::vector buffer(1024); // std::byte 타입의 동적 배열 ssize_t n = recv(sockfd, buffer.data(), buffer.size(), 0); // 메시지 받아 저장 if (n == -1) { // 에러 처리 코드... } buffer.resize(n); // 실제로 받은 데이터만큼 크기 조정 // buffer를 이용한 처리 코드... } 2023. 11. 10.
c++ 파일 라인 함수명 출력하는 매크로 #include void printLineAndFileFunction(int line, const char* file, const char* function) { std::cout 2023. 11. 7.