• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with bsd sockets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Problem with bsd sockets
      • From: Robert Tillyard <email@hidden>
  • Prev by Date: Re: Internet programming, point me?
  • Next by Date: Re: Problem with bsd sockets
  • Previous by thread: Re: Crop an image in memory
  • Next by thread: Re: Problem with bsd sockets
  • Index(es):
    • Date
    • Thread