Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:59:58+00:00 2026-05-28T07:59:58+00:00

I’ve written two functions, which should start a TCP-Server/Client. If I call them with

  • 0

I’ve written two functions, which should start a TCP-Server/Client. If I call them with the IP “127.0.0.1” (just for testing), then everything works fine. But if I call them with the public IP of my computer, I get a connection timeout. Has anybody an idea what could be the problem?

Here the Code:

Server:

bool fSTARTED = false;
struct timeval tv;

TCP_StartServer (const int iPort, SOCKET *iSOCKET)
{
WSADATA wsa;
SOCKET iSOCKETListen;
SOCKADDR_IN tAdr;

if(!fSTARTED)
{
    if(WSAStartup(MAKEWORD(2,2), &wsa))
    {
        *iSOCKET = -1;
        return;
    }
    tv.tv_sec = 5;
    tv.tv_usec = 0;
    fSTARTED = true;
}

iSOCKETListen = socket(AF_INET, SOCK_STREAM, 0);

memset(&tAdr, 0, sizeof(SOCKADDR_IN));
tAdr.sin_family = AF_INET;
tAdr.sin_port = htons(iPort);
tAdr.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(iSOCKETListen, (SOCKADDR*) & tAdr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
{
    *iSOCKET = 0 - WSAGetLastError();
    return;
}

if(listen(iSOCKETListen, SOMAXCONN) == SOCKET_ERROR)
{
    *iSOCKET =  0 - WSAGetLastError();
    return;
}

*iSOCKET = accept(iSOCKETListen, NULL, NULL);
if(*iSOCKET == INVALID_SOCKET)
{
    *iSOCKET = 0 - WSAGetLastError();
    return;
}

return;
}

Client:

TCP_StartClient (char *sIP, const int iPort, SOCKET *iSOCKET)
{
WSADATA wsa;
SOCKADDR_IN tAdr;

if(!fSTARTED)
{
    if(WSAStartup(MAKEWORD(2,2), &wsa))
    {
        *iSOCKET = -2;
        return;
    }
    tv.tv_sec = 5;
    tv.tv_usec = 0;
    fSTARTED = true;

}

*iSOCKET = socket(AF_INET, SOCK_STREAM, 0);
if(*iSOCKET == INVALID_SOCKET)
{
    *iSOCKET = 0 - WSAGetLastError();
    return;
}

memset(&tAdr, 0, sizeof(SOCKADDR_IN));
tAdr.sin_family = AF_INET;
tAdr.sin_port = htons(iPort);
tAdr.sin_addr.s_addr = inet_addr(sIP);

if(connect(*iSOCKET, (SOCKADDR*) &tAdr, sizeof(SOCKADDR)) == SOCKET_ERROR)
{
    *iSOCKET =  0 - WSAGetLastError();
    return;
}

return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:59:59+00:00Added an answer on May 28, 2026 at 7:59 am

    Here’s how a typical home computer network looks (simplified diagram and explanation):

            \     Internet     /
             \/\/\/\/\/\/\/\/\/
                      |
                      | 212.60.44.90 (public IP address)
               +-------------+
               | DSL router  |
               +-------------+
                      | 10.0.0.1 (private network router)
                      |
                      | 10.0.0.2 (private network address)
               +-------------+
               |Your computer|
               +-------------+
    

    In this case the router is doing NAT from your local 10.0.0.x addresses to your public 212.60.44.90 address. Your computer is unaware of the public IP address that it ends up using, because that information is only in the DSL router. The point of NAT is that there may also be other computers on your local 10.0.0.x network, and they share the same public IP address (because there is only one).

    Your router probably also acts as a firewall, preventing random incoming connections from the Internet from reaching your local computers. Normally the router will block all such incoming connections.

    Given the above, you should be able to see why you cannot connect to your public 212.60.44.90 address from within your own network. Your computer sends the request to the router, which either ignores or blocks your request from a firewall perspective.

    Depending on your router, you may be able to configure it to forward incoming requests to your public IP address to a specific computer on your 10.0.0.x network. You would have to set up this manually, and instructions about how to do that are beyond the scope of this answer.

    Also, you may notice that you should be able to connect to your local computer on your local network address (10.0.0.2 in the diagram). However, that’s not much more interesting than connecting to 127.0.0.1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.