任何人都可以告诉我为什么我无法阅读或写作......
int main (int argc, const char * argv[]) {
char sendbuffer[1024]= "hello world";
char recvbuffer[1024]= "";
struct sockaddr_in sin;
struct hostent *host;
int s;
host = gethostbyname("localhost");
//84.108.152.212
memcpy(&(sin.sin_addr), host->h_addr,host->h_length);
sin.sin_family = host->h_addrtype;
sin.sin_port = htons(4444);
// Create socket port 888
s = socket(AF_INET, SOCK_STREAM,0);
// 1. Block for server accept
connect(s, (struct sockaddr*)&sin,sizeof(sin));
// 2. Send "Hello world"
write(s, recvbuffer, sizeof(recvbuffer));
read(s,sendbuffer,sizeof(sendbuffer));
// Print received data
NSLog(@"Received %s\n",recvbuffer);
close(s);
return 0;
}