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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:28:33+00:00 2026-06-13T04:28:33+00:00

I am writing a simple client program socket programming when compiling the code using

  • 0

I am writing a simple client program “socket programming” when compiling the code using cygwin I got this error “undefined reference to ‘_red’
The code is below. I have been compiling with this statement gcc client.c
I really do not understand why I am getting this error. I could really use some help. The code is below.

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdlib.h>
#include <strings.h>
#include <netinet/in.h>

#define SERVER_TCP_PORT 2000
#define BUFLEN 256

int main(int argc,char **argv)
{
    int n,bytes_to_read;
    int sd,port;
    struct hostent *hp;
    struct sockaddr_in server;
    char *host,*bp,rbuf[BUFLEN],sbuf[BUFLEN];
    switch(argc) {
        case 2:
            host = argv[1];
            port = atoi(argv[2]);
            break;
        default:
            fprintf(stderr,"Usage: %s host[port] \n",argv[0]);
            exit(1);
    }
    /*Create a streamm socket*/
    if ((sd=socket(AF_INET,SOCK_STREAM,0))==-1){
        fprintf(stderr,"Can't create a socket\n");
        exit(1);
    }
    bzero ((char *)&server,sizeof(struct sockaddr_in));
    server.sin_family = AF_INET;
    server.sin_port = htons(port);
    if((hp = gethostbyname(host))==NULL){
        fprintf (stderr,"Can't get server's address\n");
        exit(1);
    }
    //bcopy(hp->h_addr,(char *)&server.sin_addr,hp->h_length);
    /*connecting to the server*/
    if (connect (sd,(struct sockaddr *)&server,sizeof(server))==-1){
        fprintf(stderr,"Can't connect \n");
        exit(1);
    }
    printf("Connected:server's address is %s\n",hp->h_name);
    printf("Transmit: \n");
    gets(sbuf);                  /*get user's text*/
    write (sd,sbuf,BUFLEN);      /*send it out*/
    printf("Receive: \n");
    bp = rbuf;
    bytes_to_read = BUFLEN;
    while ((n=red(sd,bp,bytes_to_read))>0){
        bp+=n;
        bytes_to_read -=n;
    }
    printf("%s\n",rbuf);
    close(sd);
    return(0);
}
  • 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-13T04:28:35+00:00Added an answer on June 13, 2026 at 4:28 am

    On the line

    while ((n=red(sd,bp,bytes_to_read))>0){
    

    it has red, you probably mean read

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

Sidebar

Related Questions

I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
Hi I am writing a simple client-server program. In this program I have to
I am writing simple client-server program. Client send some messages to server using UDP
Basically I am writing a simple program using the boost socket library... I have
I've been using this tutorial for a simple file transfer client/server using socket IO.
I'm writing a simple socket client which uses only one socket. So I figured
I am writing simple parallel program in C++ using OpenMP. I am working on
I am writing a simple C# tcp client and server program. The server will
i am writing a simple client/server chat program with indy 10 (blocking mode) and
I'm writing a simple console client-server app using MSMQ. I'm attempting to run it

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.