Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Im trying to program a client/server on two different computers, and make them connect, by using "SSL client example" and "SSL server example" (which are chilkat products), but they are not connecting. even though I've changed the sslServerHost (client-side) to the server's IP address. And I even turned off the AntiViruses on both computers.

NOTE: Im using Wi-Fi, and when I checked the IP address of both computers, they were the same. can this be the problem???? What shall I do!

The Server-Side Code:

C++
void Server(void)
    {

	cout<<"Server-Side\n";
	cout<<"===========\n\n";
	CkSocket listenSslSocket;

    //  Any string automatically begins a fully-functional 30-day trial.
    bool success;
	success = listenSslSocket.UnlockComponent("**********************");
    if (success != true) {
        printf("%s\n",listenSslSocket.lastErrorText());
        return;
    }

    //  An SSL server needs a digital certificate.  This example loads it from a PFX file.

    //  Create an instance of a certificate store object, load a PFX file,
    //  locate the certificate we need, and use it.
    //  (a PFX file may contain more than one certificate.)
    CkCertStore certStore;
    //  The 1st argument is the filename, the 2nd arg is the
    //  PFX file's password:
	success = certStore.LoadPfxFile("/Users/rania/My Documents/DIGITAL CERTIFICATES/MServer.pfx","***********");
	if (success != true) {
        printf("%s\n",certStore.lastErrorText());
        return;
    }

    //  Find the certificate to be used for SSL:
	CkCert *cert = 0;
	cert = certStore.FindCertBySubject("MServer");
    if (cert == 0 ) {
        printf("%s\n",certStore.lastErrorText());
        return;
    }

    //  Use the certificate:
    success = listenSslSocket.InitSslServer(*cert);
    if (success != true) {
        delete cert;
        printf("%s\n",listenSslSocket.lastErrorText());
        return;
    }

    delete cert;

    //Bind and listen on a port:
         long myPort;
	myPort = 5555;
    //Allow for a max of 5 queued connect requests.
         long backLog;
         backLog = 5;
    success = listenSslSocket.BindAndListen(myPort,backLog);
         if (success != true) {
           printf("%s\n",listenSslSocket.lastErrorText());
           return;
         }

    //  If accepting an SSL/TLS connection, the SSL handshake is part of the connection
    //  establishment process. This involves a few back-and-forth messages between the
    //  client and server to establish algorithms and a shared key to create the secure
    //  channel. The sending and receiving of these messages are governed by the
    //  MaxReadIdleMs and MaxSendIdleMs properties. If these properties are set to 0
    //  (and this is the default unless changed by your application), then the
    //  AcceptNextConnection can hang indefinitely during the SSL handshake process.
    //  Make sure these properties are set to appropriate valuescalling AcceptNextConnection.

    //  Set a 10 second max for waiting to read/write.  This is for the SSL/TLS handshake establishment.
	listenSslSocket.put_MaxReadIdleMs(10000);
	listenSslSocket.put_MaxSendIdleMs(10000);

    //  Accept a single client connection and establish the secure SSL/TLS channel:
       CkSocket *clientSock = 0;
       long maxWaitMillisec;
       maxWaitMillisec = 20000;
       clientSock = listenSslSocket.AcceptNextConnection(maxWaitMillisec);
       if (clientSock == 0 ) {
           printf("%s\n",listenSslSocket.lastErrorText());
           return;
          }

    //  The client (in this example) is going to send a "Hello Server! -EOM-"
    //  message.  Read it:
	const char * receivedMsg;
         receivedMsg = clientSock->receiveUntilMatch("-EOM-");
         if (receivedMsg == 0 ) {
            printf("%s\n",clientSock->lastErrorText());
            return;
             }

         printf("%s\n",receivedMsg);

    //Send a "Hello Client! -EOM-" message:
        success = clientSock->SendString("Hello Client! -EOM-");
        if (success != true) {
           printf("%s\n",clientSock->lastErrorText());
           return;
	}

    //Close the connection with the client
    //Wait a max of 20 seconds (20000 millsec)
        clientSock->Close(20000);

        delete clientSock;

	}



The client-Side code:

C++
<pre lang="cs">void Client(void)
    {
    CkSocket socket;

    bool success;
    success = socket.UnlockComponent("*************************");
    if (success != true) {
        printf("%s\n",socket.lastErrorText());
        return;
    }

    bool ssl;
    ssl = true;
    long maxWaitMillisec;
    maxWaitMillisec = 20000;

    //  The SSL server hostname may be an IP address, a domain name,
    //  or "localhost".  You'll need to change this:
    const char * sslServerHost;
    sslServerHost = "188.249.158.247";
    long sslServerPort;
    sslServerPort = 5555;

    //  Connect to the SSL server:
    success = socket.Connect(sslServerHost,sslServerPort,ssl,maxWaitMillisec);
    if (success != true) {
        printf("%s\n",socket.lastErrorText());
        return;
    }

    //  Set maximum timeouts for reading an writing (in millisec)
    socket.put_MaxReadIdleMs(20000);
    socket.put_MaxSendIdleMs(20000);

    //  Send a "Hello Server! -EOM-" message:
    success = socket.SendString("Hello Server! -EOM-");
    if (success != true) {
        printf("%s\n",socket.lastErrorText());
        return;
    }

    //  The server (in this example) is going to send a "Hello Client! -EOM-"
    //  message.  Read it:
    const char * receivedMsg;
    receivedMsg = socket.receiveUntilMatch("-EOM-");
    if (receivedMsg == 0 ) {
        printf("%s\n",socket.lastErrorText());
        return;
    }

    //  Close the connection with the server
    //  Wait a max of 20 seconds (20000 millsec)
    socket.Close(20000);

    printf("%s\n",receivedMsg);
    }



Best Regards.
Rania
Posted

1 solution

The simple answer is that can not have two computers on the same network with the same IP address. Network addresses are either allocated statically, by manually giving each machine an IP address, or using a DCHP server to do the IP address allocation for you. If you are connecting the two computers on a wireless network with an access point or router then they usually have a DCHP server in them. If you are doing an ad hoc connection i.e. connecting two PCs together without any other device between then you will have to use static IP addresses. The next thing that you will have to do is determine whether the subnet masks are compatible. A subnet mask consists of four numbers, like an IP address. In order for two devices to able to talk to each other then they must belong to the same subnet. If you AND the subnet mask with each of the two IP addresses then you should get the same values. For example device 192.168.1.2 can talk to 192.168.2.3 if the subnet mask is 255.255.0.0, but not if it is 255.255.255.0.

Another thing that can throw a spanner in the works is your firewall. The sender may be blocked from sending the packets or the receiver may be blocked from receiving.

A simple check would be to open up a cmd window and use the ping command to test that the two PCs can talk to each other. Once you get a ping with 100% responses then you can start looking at the software.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900