Client can not connect to the server program in the LAN
<p>I have this class constructor in C++ :</p>

<pre><code>SocketServer::SocketServer(int port)
{
    this-&gt;port=port;

WSAStartup(MAKEWORD(2,0), &amp;WSAData);
server = socket(AF_INET, SOCK_STREAM, 0);

addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);

bind(server, (SOCKADDR *)&amp;addr, sizeof(addr));
}
</code></pre>

<p>The client application with port no. 5555 can't connect to the server program on the another pc within the LAN network. I have tried different port no. too. How to resolve this? The error message is :</p>

<pre><code>Error while connecting
</code></pre>

<p>: This is client.cpp :</p>

<pre><code> #include &lt;iostream&gt;
#include &lt;fstream&gt;
#include "SocketClient.h"

using namespace std;

void onError(errorStruct *e)
{
    cout &lt;&lt; e-&gt;message &lt;&lt; endl;
}

int main()
{
    int port;
    cout&lt;&lt;"Enter a port : ";
    cin&gt;&gt;port;
    SocketClient client("127.0.0.1", port);
    client.setErrorCallback(onError);
   client.connect();

string str;
while(1)
{
    cout &lt;&lt; "&gt;";
    getline(cin, str);
    client.send(str);
}

client.close();
}
</code></pre>

<p>Edit 2 : SocketClient</p>

<pre><code>SocketClient::SocketClient(std::string ip, int port)
{
    this-&gt;ip=ip;
    this-&gt;port=port;
    this-&gt;connected=false;
    initParameters();
    initSocket(ip, port);
}

void SocketClient::initSocket(std::string ip, int port)
{
    WSAStartup(MAKEWORD(2,0), &amp;WSAData);
    this-&gt;socket = WINSOCK_API_LINKAGE::socket(AF_INET, SOCK_STREAM, 0);
    this-&gt;addr.sin_addr.s_addr = inet_addr(ip.c_str());
    this-&gt;addr.sin_family = AF_INET;
    this-&gt;addr.sin_port = htons(port);
}

void SocketClient::initParameters()
{
    this-&gt;bytes_for_package_size=16;
    this-&gt;size_of_packages=2048;
    this-&gt;callback=NULL;
    this-&gt;callbackError=NULL;
    this-&gt;thread_started=false;
    this-&gt;errorWhileReceiving=false;
    this-&gt;errorWhileSending=false;
}
</code></pre>