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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:04:39+00:00 2026-05-31T12:04:39+00:00

I’m trying to work with sockets in C++. The only work with sockets I

  • 0

I’m trying to work with sockets in C++. The only work with sockets I have ever done was in Java (I created an IRC bot, to be specific) and the code I used looked like the following –

Socket socket = new Socket(host, port);
BufferedWriter writer = new BufferedWriter(
                             new OutputStreamWriter(socket.getOutputStream()));
BufferedReader reader = new BufferedReater(
                             new InputStreamWriter(socket.getInputStream()));

then for my bot to read I would get a new thread and initiate a while loop –

String line;
while((line = reader.readLine()) != null) ...

And to write –

writer.write(text);
writer.flush();

Now I’m attempting to do so in C++ and things are of course at a lower level and I don’t quite understand what I’m doing. I looked for some tutorials on using winsock.h and tried them all to no avail. A friend of mine recommended the socket library sdl_net.

My question is how would my code in C++ look different compared to the code I used for my IRC bot in Java? Also, what is the difference between the “Buffered” streams in Java and my lower-level socket work in C++?

  • 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-31T12:04:39+00:00Added an answer on May 31, 2026 at 12:04 pm

    To answer your main question, this tutorial shows you roughly what the C++ would look like:

    http://www.linuxhowtos.org/C_C++/socket.htm

    http://www.linuxhowtos.org/data/6/client.c

    Fundamentally, you need to use the socket() and connect() calls to instead of new Socket().

    The C++ streams are similar to the raw socket.get(Output|Input)Stream() streams in that there is no buffering being performed. The Buffered(Output|Input)Stream stores the written/read bytes in a buffer instead of writing through to the underlying stream for every call to write()/read(). Calling flush() forces the buffered data to be written through.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

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.