Problem with bsd sockets
Problem with bsd sockets
- Subject: Problem with bsd sockets
- From: Quentin Mathé <email@hidden>
- Date: Fri, 3 Jan 2003 20:22:07 +0100
When I run the code below in Cocoa application with Project Builder, I
get an error : socket already connected everytime, even when my
internet connection is turned off. I have found no explanation about
this problem in the book Unix network programming I hope someone can
help me
int sockfd; // socket file descriptor
struct sockaddr_in serverAddress;
char buffer[201];
int n;
if (sockfd = socket(AF_INET, SOCK_STREAM, 0) < 0) {
perror("socket");
exit(1);
}
bzero(&serverAddress, sizeof(serverAddress));
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(80);
inet_pton(AF_INET, "17.112.152.32", &serverAddress.sin_addr);
if (connect(sockfd, (struct sockaddr*)&serverAddress,
sizeof(serverAddress)) < 0) {
perror("connect");
}
while (n = read(sockfd, buffer, 200) > 0) {
buffer[n] = 0;
printf(buffer);
}
if (n < 0) {
perror("read");
}
close(sockfd);
--
Quentin Mathi
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.