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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:18:48+00:00 2026-06-01T09:18:48+00:00

I am trying to implement a simple code tester : a very basic version

  • 0

I am trying to implement a simple code tester : a very basic version of the ACM ICPC or Google Code Jam online judger.

The evaluation part works (so far) but I’m stuck silly at the file transfer part.

Basically my setup is this :

I have a server (always on) and multiple client systems belonging to teams who’ll submit their code. They may transfer files amongst one another within a team, but the server will keep a log of transfers. The server may sometimes send announcements to all or certain clients. The final code will be submitted to a particular empty client machine for evaluation.

Now, my server side code is having trouble. I’m using

select(fdmax+1, &read_fds, NULL, NULL, NULL)

to identify clients ready for writing data to me – I’m aware this polling can be done by fork() somehow but I’m neither sure nor comfortable about it.

For receiving the data to the server I’m using the following function :

void send_recv(int i, fd_set *master, int sockfd, int fdmax)
{
    int nbytes_recvd, j;
    char recv_buf[BUFSIZE], buf[BUFSIZE];

    if ((nbytes_recvd = recv(i, recv_buf, BUFSIZE, 0)) <= 0) {
        if (nbytes_recvd == 0) {
            printf("socket %d hung up\n", i);
        }else {
            perror("recv");
        }
        close(i);
        FD_CLR(i, master);
    }else {
        FILE *logger;
        logger = fopen(fname2, "w");
        fprintf(logger,"Client %i> %s", i,recv_buf);
        for(j = 0; j <= fdmax; j++){
            send_to_all(j, i, sockfd, nbytes_recvd, recv_buf, master );
        }
    }
}

Here, instead of logging all file data being transferred over the stream separately, I’m getting a jumbled mess that is hard to parse.

This function is actually transferring the files (all ANSI *.c) :

void send_to_all(int j, int i, int sockfd, int nbytes_recvd, char *recv_buf, fd_set *master)
{
    if (FD_ISSET(j, master)){
        if (j != sockfd && j != i) {    //prevents data rewrite to incoming host
            int client;
            sscanf(recv_buf, "%d >", &client);
            if(client == 0){                //universal send
                if (send(j, recv_buf, nbytes_recvd, 0) == -1) {
                    perror("send");
                }
            }                               //send to specified host
            else if (send(client, recv_buf, nbytes_recvd, 0) == -1) {
                perror("send");
            }
        }
    }
}

Here the incoming files lose all their formatting and gets printed twice every time.

A stripped down version of my server code is here : http://codepad.org/TTejTfbL

My question is, am I doing something fundamentally wrong ? Is my logic (and, by extension, my code) irretrievably broken ?

I’d be gratified if someone could point me in the right direction.
Or even tell me to throw it all away and start from scratch. (^;__;^)

  • 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-01T09:18:49+00:00Added an answer on June 1, 2026 at 9:18 am

    You can’t assume that you can send() any amount of data in a single call, and have it monotlithically succeed or fail. There are limits to the buffers implemented by the library.

    It’s perfectly possible for you to pass e.g. 20 KB to send(), and have it successfully return after sending only 4,711 bytes. That would require you to step forward in your buffer by the proper amount, decrease the “bytes to go”, and try again.

    This needs to be looped until you’ve sent all your data, or received an I/O error from the socket.

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

Sidebar

Related Questions

I'm trying to implement the simple-linkedinphp library (it's found at http://code.google.com/p/simple-linkedinphp/ ) It runs
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
I'm trying to implement a simple Pub/Sub object in javascript, and here's my code:
I'm trying to implement a very simple way to select a subsection of the
This maybe a very noobish question but I am trying to implement a simple
I'm trying to implement a simple LinkedList The following code, producing this error: error:
I am trying to implement a simple string copy in the following code. However,
I've been trying to implement simple low level keyhook using JNI and all went
I'm getting acquanted with Core Animation and trying to implement simple movement along a
Just trying to implement a simple audit logging solution with Grails 2.0.2 and 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.