
socket_atmark는 TCP/IP 소켓 프로그래밍에서 데이터 전송을 구분하는 특수한 문자열입니다. '@' 기호를 의미하며, 데이터 전송의 구분점을 나타냅니다.
socket_atmark는 TCP/IP 소켓 프로그래밍에서 데이터를 전송할 때, 데이터를 구분하는 데 사용됩니다. 예를 들어, 서버가 클라이언트에게 데이터를 전송할 때, socket_atmark를 사용하여 데이터를 구분할 수 있습니다.
socket_atmark를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
c
#include
#include
#include
#include
#include
#include
#define PORT 8080
#define BUFFER_SIZE 1024
int main() {
int server_fd, client_fd;
struct sockaddr_in server_addr, client_addr;
socklen_t client_len = sizeof(client_addr);
char buffer[BUFFER_SIZE];
char message[] = "Hello, client!@";
// 서버 소켓 생성
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd < 0) {
perror("socket creation failed");
exit(1);
}
// 서버 주소 설정
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);
// 서버 소켓 바인딩
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
perror("bind failed");
exit(1);
}
// 서버 소켓 리스닝
if (listen(server_fd, 3) < 0) {
perror("listen failed");
exit(1);
}
printf("서버가 시작되었습니다.n");
while (1) {
// 클라이언트 연결.accept()
client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_len);
if (client_fd < 0) {
perror("accept failed");
continue;
}
printf("클라이언트와 연결되었습니다.n");
// 데이터 수신
int bytes_received = recv(client_fd, buffer, BUFFER_SIZE, 0);
if (bytes_received < 0) {
perror("recv failed");
continue;
}
// 데이터 처리
printf("클라이언트로부터 받은 데이터: %sn", buffer);
// 데이터 전송
send(client_fd, message, strlen(message), 0);
// 클라이언트 연결 종료
close(client_fd);
}
return 0;
}
이 예제에서는 서버가 클라이언트에게 데이터를 전송할 때, socket_atmark를 사용하여 데이터를 구분합니다. 클라이언트는 서버로부터 받은 데이터를 처리하고, 서버는 클라이언트에게 데이터를 전송합니다.
2025-07-15 16:08