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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:25:53+00:00 2026-05-27T19:25:53+00:00

I am reading and writing to sockets using fread() and fwrite(). These functions, I

  • 0

I am reading and writing to sockets using fread() and fwrite(). These functions, I believe are for buffered input and output. Is there some way that I can disable buffering while still using these functions ?

Edit :

I am building a remote desktop application and the remote client seems to be “lagging a bit behind the server”, and I dont have any idea what may be the reason… I thought it may be because of buffered read and write .. but using setvbuf didnt work.

By “lagging”, I mean that the remote desktop client is running a few seconds behind the server. What the server is doing at a particular moment is reflected on the client side after a delay of some 15-20 seconds.

Also, I dont want to not-use-fread(), because it is a part of existing code. I don’t want to modify it. I could eventually use write() and read(), but I would like to avoid it.

  • 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-05-27T19:25:53+00:00Added an answer on May 27, 2026 at 7:25 pm

    You can use setvbuf to disable buffering for a specific file pointer:

    setvbuf(fp, NULL, _IONBF, 0);
    

    EDIT

    Mixing sockets with standard input is kind of tricky, as warned by Stevens. Here are a few quotes.

    The problem problem with these latter three functions [fseek, fsetpos, rewing] is that
    they all call lseek, which fails on a socket.

    The easiest way to handle this read-write problem is to open two
    standard I/O streams for a given socket: one for reading and one for
    writing
    .

    One way around this [buffering problem] is to force the output stream
    to be line buffered by calling setvbuf. Another is to force each
    echoed line to be output by calling fflush after each call to fputs.
    But in practice, either of these solutions is still error-prone and
    may interact badly with the Nagle algorithm


    In conclusion:

    Try to stop using stdio. It makes no sense to use stdio and fread and fwrite. Use straight read and write instead. Stevens speaks of “line buffered” output because people use fgets and fputs with stdio

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

Sidebar

Related Questions

Possible Duplicate: Reading/Writing MS Word files in Python I know there are some libraries
What is the preferred method for reading/writing to TCP/IP sockets in PHP? There are
I want to know the files a given process is reading/writing. Is there a
I am writing a client-server application using TCP Sockets. The server is written in
I'm writing a multi-threaded server using boost::asio (for sockets), boost::thread (for threading), libconfig++ (for
I writing a command and then reading back from a server via sockets in
I'm writing a simple telnet client library. I open sockets using fsockopen() and read
I am using 2 threads- ReaderThread for reading from the Socket input stream and
While implementing XML file reading/writing in my application I saw that when I call
I have just been getting into low level programming (reading/writing to memory that sort

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.