데이터를 "수신"으로 설정 한 경우 "송신"(첫 번째) 또는 "전환" 다른 컴퓨터에서 보낸 "(처음)?"보내기/받기"또는 "받기/보내기"중 하나를 수행하도록 소켓을 설정하는 방법
감사
일반적인 코드 :
-(void) TcpClient{
char buffer[128];
struct sockaddr_in sin;
struct hostent *host;
int s;
host = gethostbyname("10.0.0.3");
memcpy(&(sin.sin_addr), host->h_addr,host->h_length);
sin.sin_family = host->h_addrtype;
sin.sin_port = htons(4000);
s = socket(AF_INET, SOCK_STREAM, 0);
connect(s, (struct sockaddr*)&sin, sizeof(sin));
while(1){//this is the Client sequence:
send(s, buffer, strlen(buffer), 0);//but what if the Server sends first ?? Client needs to receive here first
recv(s, buffer, sizeof(buffer), 0);
}
close(s);
}
차단 해제를 설정해야합니까? – jdl
아니요,'select()'는 블로킹 소켓과 비 블로킹 소켓 모두에서 작동합니다. –