Beginner: Sending data over sockets - c++

Can anyone find an example of a simple server/client thing? I'm willing to use any C++ library or even Winsocks it self. I've Googled around but want some opinion on a good article for beginners/sites.

If you're willing to use a C++ library, I heartily recommend Qt. It gives you an easy way to communicate with sockets, and much more. In particular see the QtNetwork module - a few of its relevant classes for your cause: QTcpSocket, QTcpServer, QUdpSocket.

see
http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html

If you are looking for a C++ networking library, I suggest Asio, which is now part of Boost. Start with the Tutorial. Also have a look at the examples.

JFGI
http://www.adp-gmbh.ch/win/misc/sockets.html
http://tldp.org/LDP/LG/issue74/tougher.html

I like ACE. It is a pretty large library but there are some core classes that are really easy to use for beginning network programming.
Here's a really good book for ACE too.
Ace Programming Guide

Related

C++ Object Oriented libraries

I'm mainly a java programmer and I'm getting started with C++.
I wonder if you could help me finding a java-like object-oriented library.
Thanks and regards
I would rather suggest you to not use java-like libraries. If you want to learn C++ first dig into the standard library. Try to understand the concepts used there (iterator, allocators, templates, ...)
I found this a good source of information related to the STL.
C++ as language is far more complex than java so the learning curve is straight, but after you got the basics you can write fancier, cleaner and achieve more with less code.
Well designed libraries
Boost Multiple purpose (Networking, Threading, Smart Pointers, ...)
QT UI library, multiple purpose
I learned C# before I had to write C++, so I understand your issue. Try not to write everything object oriented. You just don't in C++.
Ice for communications.
Multipurpose Boost library.
My advice would be to get used to the C++ languages and the standard library. This is how you will learn C++.
I don't know if there is a good answer to your question, unfortunately. But if you like you could always interface from Java to C using JNI.
My advice: write a 10-20 console applications in pure ะก++. Then try to use templates. Then communication through network. And then, IF you feel comfortable with syntax and commonly used libraries like STL and BOOST, you can try GUI toolkits like wxWidgets, QT, GTK.
Trying to write GUI applications from the begining seems to me a bad practice.

C++ File Sending Program

So I need to introduce myself to sockets and general network programming. I consider myself fluent in C++, but I basically can build stuff with the basics of C++ (think having only a basic set of legos)
Now I really need to venture forth and expand my lego set to different pieces (pardon the lego metaphor) But socket programming/network is my next target. So I thought a simple program to write would be a file sending program.
Basically a program that you type in the IP of your friend, (he has the program too) and it asks "Would you like to receive fileXXX.yyy" If he says yes, then it proceeds to send the file.
I know i'd need to know about sockets, but what else would I need to know about? Should this be a simple program to accomplish? Any recommended tutorials I read before I dive head first?
Any additional info is helpful. Thanks. And NO this is not for school, it's just kinda something I wanna learn.
C++ preferred language.
You should get yourself the boost libraries.
There is no standard socket API for C++ but boost provides one in their ASIO library that will work on multiple platforms (as is the case with all boost libraries).
beej has a good guide for unix socket programming:
http://beej.us/guide/bgnet/
You can use the same code on a windows platform if you include the winsock library and an additional startup call
The Boost.Asio library mentioned in CashCow's answer is a fantastic cross-platform and easy to use library. Don't let the asynchronous name scare you, it can be a bit daunting at times but the documentation is straightforward and easy to understand.
The boost-asio tag is also fairly active on stack overflow.

C++ Libraries similar to C#?

I'm coming to C++ from a .Net background. Knowing how to use the Standard C++ Libraries, and all the syntax, I've never ventured further. Now I'm looking learning a bit more, such as what libraries are commonly used? I want to start getting into Threading but have no idea to start. Is there a library (similar to how .net has System.Threading) out there that will make it a bit easier? I'm specifically looking to do Linux based network programming.
For C++, Boost is your everything. Threading and networking are among the things it offers. But there's much more:
Smart pointers
Useful containers not found in the STL, such as fixed-size arrays and hashtables
Closures
Date/time classes
A foreach construct
Min/max functions
Command line option parsing
Regular expressions
As the others have said, Boost is great. It implements the C++ Technical Report 1 in addition to tons of other stuff, including some mind-blowing template metaprogramming tricks.
For other cross-platform features not provided by Boost, I've had very good luck with a library called Poco. I've worked on commercial projects that incorporated its simple HTTP server, for instance, and it treated us quite well.
lots of boost suggestions, but Qt is another good option. It's got great support for threading and networking along with pretty much everything else.
http://qt.nokia.com/products
If you are looking into network programming and are not interested into GUI, I suggest Boost libraries: in particular, Asio.
There's no standard multithreading library, but the boost library includes a platform-independent multithreading abstraction that works very well.

Network programming using C++

How can we do network programming in C++ similar to Remoting in .NET? Please help with any tutorials.
It would be fine if I know how to enable two computers to communicate in the form of sending and receiving messages using C++/C#.
Thanks,
Rakesh.
For windows, you can check out this.
You could refer Beej's guide for Unix flavors.
C++ does not have any native networking libraries, so if you don't want to use OS specific calls, you are going to need to use a portability layer.
Two that come to mind are Boost ASIO and ACE.
You may want to have a look at the Poco C++ libraries. Especially the Net module.
For a pure C++ solution (as your first sentence suggests) that's also really simple to use, checkout RCF.
If you want to communicate between C# and C++ programs (as your second sentence suggests) you'll have to look elsewhere, sorry.
Check out our C++ Remoting framework. There's also a screencast showing how to use it.
This is probably the closest that you'll get to .NET Remoting in C++.

How to use the C++ Sockets Library

I'd like to do some network socket programming in C++ and have found the C++ Sockets library.
First, is this a good way to go in C++? Normally in C, I'd use some of the stuff beej describes in his tutorial.
Second, how do I compile the examples given on the site? I can't figure it out from their installation/configuration guide. So I download the tar.gz to my Linux box, then what?
To have a specific example, how do I compile and run the DisplaySocket example?
Thanks.
EDIT: Thank you for the quick answers. A comment though. I'm not really looking into "understanding" network programming as I think I do that well enough already. I want to know if there's anything in particular to take advantage of in C++, and - if "the C++ Sockets Library" is a good choice - how to use it.
That's not "the" C++ sockets library, it's "a" C++ sockets library. Boost.asio has another (http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio.html).
(Community Wiki since I can't actually help you with your question - I've never compiled the code you ask about, so I don't know at what point you might have tripped over a problem).
Network programming would be better understood by using basic socket api (BSD or WinSock) rather than a socket library which hides most of the intricacies about sockets and their behaviour.
I would second the vote for boost::asio since it encapsulates the inversion of control model that is the current, preferred model, and appears to be standard-bound. To learn what the documentation doesn't tell you, google Douglas Schmidt and his books.
I like to use the ACE networking library when I write networking code in C++. I think it does a nice job abstracting some of the intricate details away that make network coding painful but doesn't do it to the point where it hides what is going on under the hood. It also has facilities for threading and messaging which usually are needed for any project.