Thread: Socket communication hanging

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    So are you for sure always sending MAXDATASIZE bytes? I mean, is the file you're sending always that length? If not, then that's your problem. You need to write() exactly the same number of bytes as is the length of the file you're sending. You can get this information from the return value of fread().

    And when your client read()s the data from the socket, read() returns the number of bytes received and that's where you should be null-terminating the read buffer (i.e. bytes_received = read(sockfd, buf, MAXDATASIZE); buf[bytes_received] = '\0'; )
    Last edited by itsme86; 08-05-2004 at 05:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  3. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  4. problem closing a socket
    By Wisefool in forum C Programming
    Replies: 1
    Last Post: 10-28-2003, 01:38 PM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM