Join Today
+ Reply to Thread
Results 1 to 3 of 3
  1. Default unable to socket connect

    I am using an A780 with T-Mobile service and attempting to use sockets in my c++ application. After my orginal application did not work I attempted to ping www.google.com and that does not work either. My application and ping just hang there. I can use the browser to browse the web. Anyone know how to connect to the outside world using sockets? Below is my simple application.

    TC


    int main(int argc, char** argv)
    {
    std::string strHost;
    int nPort = 0;

    if ( argc < 3 )
    {
    std::cerr << "must supply ip and port" << std::endl;
    return -1;
    }

    strHost = argv[1];
    nPort = atoi(argv[2]);


    struct sockaddr_in dest_addr;
    int sock = socket(AF_INET, SOCK_STREAM, 0);

    if ( sock < 0)
    {
    perror("Could con create socket:");
    return -1;
    }

    std::cerr << "Created socket" << std::endl;

    struct hostent *hostInfo;
    hostInfo = gethostbyname(strHost.c_str());
    if (hostInfo == NULL) {
    std::cout << "problem interpreting host: " << strHost.c_str() << std::endl;
    return -1;
    }

    std::cerr << "Got host information" << std::endl;


    dest_addr.sin_family = hostInfo->h_addrtype; /* host byte order */
    memcpy((char *) &dest_addr.sin_addr.s_addr,
    hostInfo->h_addr_list[0], hostInfo->h_length);

    dest_addr.sin_port = htons(nPort); /* short, network byte order */

    /* don't forget to error check the connect()! */
    int nReturn = connect(sock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));

    if (nReturn<0)
    {
    perror("Cannot connect:");
    close(sock);
    return -1;
    }

    std::cerr << "Connected" << std::endl;
    close(sock);

    return 0;

    }

  2. #2

    Default Re: unable to socket connect

    Can you telnet to www.google.com:80 from the phone? That would confirm that TCP is working fine. Maybe you or your provider are not allowing ICMP packets (it is a cellphone, after all) which would prevent ping from working.

    The code looks fine after a quick skim, assuming it compiles. I have not tested it, but just as a tip, you might want to try copying to pastebin.com or something and linking us there. Its hard to read without indenting =)

    Does your program give you ANY output at all? if you are not even getting the 'Create Socket' error, then your problems probably lie elsewhere. How are you compiling it? Does it work on an i386 linux system?

  3. Default Re: unable to socket connect

    A couple more tests:

    1) ran my program and connecting back to my computer that I have connected via usb. That works so program 192.168.1.1 22 (i have an ssh server running)

    2) created a lin script to run my program with www.google.com 80 and redirected the output to a file in diska. I run the lin script without my computer connected to the cellphone just incase there was a routing issue. I get the same results. Which is the socket is created, I get the host name and then it hangs on attempting to connect. I added a couple more cerr calls so I know exactly where the program hangs.

    3) I ran my program on my computer with FC4 arguments www.google.com 80 and it works


 
+ Reply to Thread

Similar Threads

  1. Unable to connect E6 with PC
    By mahendrupuneet in forum E6 General Chat
    Replies: 3
    Last Post: 12-13-2008, 08:34 AM
  2. Help: Unable to connect to Gmail!
    By mananwala in forum A1200 General Chat
    Replies: 26
    Last Post: 06-18-2008, 06:59 PM
  3. unable to connect to e680
    By brio48 in forum E680 General Chat
    Replies: 0
    Last Post: 02-08-2008, 04:06 PM
  4. Help: Unable to connect to intenet with my browser!
    By megaman12 in forum A1200 General Chat
    Replies: 4
    Last Post: 12-05-2007, 12:57 AM
  5. Unable to connect with Cingular
    By stephanghunter in forum A1200 General Chat
    Replies: 2
    Last Post: 08-27-2006, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Single Sign On provided by vBSSO

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1