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 8593623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:02:07+00:00 2026-06-12T00:02:07+00:00

I’ve installed Windows 8 64bits and Visual Sudio 2012. Later, in class, the teacher

  • 0

I’ve installed Windows 8 64bits and Visual Sudio 2012.

Later, in class, the teacher gave us a .cpp file to try a udp server on our computer.
It should be just run and use but, in my case, VS is giving me some unresolved externals

#include <stdio.h>
#include <winsock.h>


#define GET_TIME "TIME\r\n"
#define MAX_MSG_SIZE 100

void processClient(LPVOID param);

void main(int argc, char **argv)
{
    SOCKET s, cliSocket;
    WSADATA wsaData;
    int iResult, len;
    struct sockaddr_in serv_addr, cli_addr;
    SECURITY_ATTRIBUTES sa;
    DWORD thread_id;

    if(argc != 2){
        printf("Usage: %s  <time_server_port>\n", argv[0]);
        getchar();
        exit(1);
    }

    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (iResult != 0) {
        printf("WSAStartup failed: %d\n", iResult);
        getchar();
        exit(1);
    }

    if((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == SOCKET_ERROR){
        printf("Unable to create socket (error: %d)!\n", WSAGetLastError());
        getchar();
        exit(1);
    }

    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(atoi(argv[1]));

    if(bind(s, (struct sockaddr *)&serv_addr, sizeof(serv_addr))==SOCKET_ERROR){
        printf("Unable to bind socket to port %s (error: %d)\n", argv[1], WSAGetLastError());
        closesocket(s);
        getchar();
        exit(1);
    }

    listen(s, 5);

    while(1){

        printf("Waiting for a time request...\n");

        len = sizeof(cli_addr);

        if((cliSocket = accept(s, (struct sockaddr *)&cli_addr, &len))==SOCKET_ERROR){
            printf("Unable to accept new connection (error: %d)\n", WSAGetLastError());
            closesocket(s);
            getchar();
            exit(1);
        }

        printf("Connection from %s:%d accepted\n", inet_ntoa(cli_addr.sin_addr),
                    ntohs(cli_addr.sin_port));


        sa.nLength=sizeof(sa);
        sa.lpSecurityDescriptor=NULL;

        if(CreateThread(&sa,0 ,(LPTHREAD_START_ROUTINE)processClient, (LPVOID)cliSocket, (DWORD)0, &thread_id)==NULL){
            printf("Cannot start new slave thread (error: %d)\n", GetLastError());          
            closesocket(cliSocket);
        }

        printf("New slave thread started (id: %d)\n", thread_id);           
    }
}

void processClient(LPVOID param)
{
    SOCKET s;
    int nbytes, len;
    struct sockaddr_in cli_addr;
    char request[MAX_MSG_SIZE], response[MAX_MSG_SIZE];
    SYSTEMTIME systemTime;

    s = (SOCKET)param;

    if((nbytes = recv(s, request, MAX_MSG_SIZE, 0)) == SOCKET_ERROR){

        printf("Unable to receive request (error: %d)\n", WSAGetLastError());
        closesocket(s);
        return;
    }

    request[nbytes] = 0;
    if(strcmp(GET_TIME, request)!=0){
        printf("Unexpected request \"%s\" will be ignored\n", request);
        closesocket(s);
        return;
    }

    GetSystemTime(&systemTime);
    sprintf(response, "%d:%d:%d", systemTime.wHour,
                        systemTime.wMinute, systemTime.wSecond);

    if(send(s, response, strlen(response), 0) == SOCKET_ERROR){
        printf("Unable to send reponse (error: %d)\n", WSAGetLastError());
        closesocket(s);
        return;
    }

    len = sizeof(cli_addr);
    getpeername(s, (struct sockaddr *)&cli_addr, &len);
    printf("\"%s\" sent to %s:%d\n", response, inet_ntoa(cli_addr.sin_addr),
                    ntohs(cli_addr.sin_port));

    closesocket(s);
}

These are the errors:

1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _accept@12 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _bind@12 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _closesocket@4 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _getpeername@12 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _htonl@4 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _htons@4 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _inet_ntoa@4 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _listen@8 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _ntohs@4 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _recv@16 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _send@16 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main
1>TCPConcurrentServer.obj : error LNK2019: unresolved external symbol _WSAGetLastError@0 referenced in function "void __cdecl processClient(void *)" (?processClient@@YAXPAX@Z)
1>c:\users\brunoc\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 14 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Does someone knows how to solve this?
Thanks

  • 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-12T00:02:08+00:00Added an answer on June 12, 2026 at 12:02 am

    Open the Project properties, go to Linker -> Input, and the add the ws2_32.lib to Additional Dependencies edit line.

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.