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

  • SEARCH
  • Home
  • 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 7729823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:04:07+00:00 2026-06-01T06:04:07+00:00

The code below is creating a server to communicate with clients.This code works fine

  • 0

The code below is creating a server to communicate with clients.This code works fine over HTTP but does not work correctly in HTTPS. Suggest a method or network function need to be included to work fine over ssl.

#define SOCKET_OK 0

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, 
                               LPSTR lpCmdLine, int nShow)
{
WORD sockVer;
WSADATA wsaData;
int retVal;

sockVer = MAKEWORD(2,2);

WSAStartup(sockVer, &wsaData);

/// Creating socket
SOCKET servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

if(servSock == INVALID_SOCKET)
{
    MessageBox(NULL, "Unable to create socket()", "SOCKET ERROR", MB_OK);
    WSACleanup();
    return SOCKET_ERROR;
}

/// Filling in sockaddr_in struct 

SOCKADDR_IN sin;
sin.sin_family = PF_INET;
sin.sin_port = htons(1111);
sin.sin_addr.s_addr = INADDR_ANY;

retVal = bind(servSock, (LPSOCKADDR)&sin, sizeof(sin));
if(retVal == SOCKET_ERROR)
{
    MessageBox(NULL, "Unable to bind", "SOCKET ERROR", MB_OK);
    WSACleanup();
    return SOCKET_ERROR;
}

/// Trying to listen socket
retVal = listen(servSock, 10);
if(retVal == SOCKET_ERROR)
{
       MessageBox(NULL, "Unable to listen()", "SOCKET ERROR", MB_OK);
    WSACleanup();
    return SOCKET_ERROR;
}

/// Waiting for a client
SOCKET clientSock;

clientSock = accept(servSock, NULL, NULL);

if(clientSock == INVALID_SOCKET)
{
    MessageBox(NULL, "Unable to accept()", "SOCKET ERROR", MB_OK);
    WSACleanup();
    return SOCKET_ERROR;
}

char szReq[8]; 
retVal = recv(clientSock, szReq, 8, 0);

if(retVal == SOCKET_ERROR)
{
    MessageBox(NULL, "Unable to recv()", "SOCKET ERROR", MB_OK);
    return SOCKET_ERROR;
}

MessageBox(NULL, szReq, "Got the request from client", MB_OK);


char *szResp = "Response";

MessageBox(NULL, szResp, "Sending response from server", MB_OK);
retVal = send(clientSock, szResp, strlen(szResp), 0);

if(retVal == SOCKET_ERROR)
{
    MessageBox(NULL, "Unable to send()", "SOCKET ERROR", MB_OK);
    return SOCKET_ERROR;
}

/// Closing socket
closesocket(clientSock);
closesocket(servSock);

WSACleanup();

return SOCKET_OK;
}
  • 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-06-01T06:04:08+00:00Added an answer on June 1, 2026 at 6:04 am

    Socket is a lower-level protocol than http and https – http and https run on top of it. Your apprach using socket should work with https – but you are going to get the raw, encrypted data – that is probably not what you want.

    I suggest you look into using higher-level classes – like WinInet: http://msdn.microsoft.com/en-us/library/3w2azyt6.aspx

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

Sidebar

Related Questions

I am creating an iphone app with xmpframework, everything works fine, but i would
The below code works great for creating Unique Constraints : ALTER TABLE <tablename> ADD
In the code below is the initial first loop needed when creating a 2D
I am creating a random ID using the below code: from random import *
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT
The code below doesn't seem to work or find anything on an array. I'm
I have the code below. The line string content = twitterMsg.text; is creating the
I consistently get the error 'failed creating formpost data' from the below code, the
I'm getting exception while creating connection with SQL Server. ISession factory is shown below
I have a java server on a server socket. Clients connect to this server

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.