• 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
why does this code NOT work on macbookpro?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why does this code NOT work on macbookpro?


  • Subject: why does this code NOT work on macbookpro?
  • From: Perry Winkel <email@hidden>
  • Date: Sun, 17 Sep 2006 17:50:16 +0200

#include <iostream>
#include <errno.h>
#include <string.h>

#include <unistd.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

int main (int argc, char * const argv[]) {
std::cout << "hello world\n";

int myposixsocketnumber=socket(AF_INET,SOCK_STREAM,0);
std::cout << "myposixsocketnumber:" << myposixsocketnumber << "\n";

sockaddr_in mysockaddrin;
{
mysockaddrin.sin_family=AF_INET;
mysockaddrin.sin_addr.s_addr=inet_addr("192.168.1.38");
// mysockaddrin.sin_port=2162;
mysockaddrin.sin_port=80;
}

std::cout << "connect ip:" << mysockaddrin.sin_addr.s_addr << " port:" << mysockaddrin.sin_port << "\n";

int myresult=connect(myposixsocketnumber,(sockaddr*)&mysockaddrin,sizeof(mysockaddrin));
std::cout << "myresult:" << myresult << "\n";


if(myresult){
std::cout << "errno:" << errno << " strerror(errno):" << strerror(errno) << "\n";
}

char *mymessage="are_you_ok\n\n"; ssize_t mymessagelen=(size_t)strlen(mymessage);
ssize_t mylenwritten=write(myposixsocketnumber,mymessage,mymessagelen);
std::cout << "mylenwritten:" << mylenwritten << "\n";

return 0;
}

run info with output

perry-mb:~/sockettest za$ g++ main.cpp
perry-mb:~/sockettest za$ ./a.out
hello world
myposixsocketnumber:3
connect ip:637642944 port:80
myresult:-1
errno:61 strerror(errno):Connection refused
Broken pipe
perry-mb:~/sockettest za$

if i type in my console i het GOOD results

perry-mb:~/sockettest za$ telnet 192.168.1.38 80
Trying 192.168.1.38...
Connected to 192.168.1.38.
Escape character is '^]'.
hello

Connection closed by foreign host.
perry-mb:~/sockettest za$

code works fine on my old powerbook (10.3)

--
would really appreciate any help

met vriendelijke groeten
perry winkel



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: why does this code NOT work on macbookpro?
      • From: "Clark Cox" <email@hidden>
    • Re: why does this code NOT work on macbookpro?
      • From: Alexander von Below <email@hidden>
  • Prev by Date: Re: ICEberg // Integration of package generation into Xcode ?
  • Next by Date: Re: why does this code NOT work on macbookpro?
  • Previous by thread: Re: newbie:: __FILE__
  • Next by thread: Re: why does this code NOT work on macbookpro?
  • Index(es):
    • Date
    • Thread