Filip Ekberg
Filip Ekberg

Reputation: 36287

Problem with Closing Sockets. Program Halts

I am having some trouble with this code. The problem is when i Request the Server to send me some data and the client just Disconnects when the server tries to send me data, the application Exists.

Here's the lines I think cause the problem

int SendBinary(int *byte, int length)
{
    int bytes_sent;

    bytes_sent = send(connecting_socket, byte, length, 0);

    return bytes_sent;


    return 0;
}

void SendFile(FILE *fp, int file_size)
{
    int current_char = 0;

    do{
        current_char = fgetc(fp);

        if ( current_char == EOF )
            break;

        SendBinary(&current_char, sizeof(char));
    }
    while(current_char != EOF);

}

Any ideas what i should do to prevent this? Revise the whole source for complements to this snippet.

Upvotes: 1

Views: 206

Answers (2)

qrdl
qrdl

Reputation: 34948

Are you sure client didn't fail on receiving the data from server?

  1. telnet to your server to see what it sends in response

  2. Replace your server with netcat to make sure client is behaving correctly

  3. Sniff the traffic between server and client using tcpdump or similar tool

Upvotes: 0

Greg Rogers
Greg Rogers

Reputation: 36429

Perhaps your application is receiving SIGPIPE during the write/send and not ignoring it? Try ignoring this signal or installing a do-nothing handler for it.

Upvotes: 6

Related Questions