LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2011, 01:53 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
What are the 'must know' concepts in the socket programming?


I have worked previously with the Qt UDP and TCP sockets. We had to read from the sockets, store it somewhere, flush the buffer and read again and write.

But there must be something more to socket programming than just to read and write.

If I say I "know" socket programming, what the things, that are expected to be under my belt?

P.S:
People on StackOverflow told me to read about 'serialization' and 'apache thrift'.

Any other inputs are welcome.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-07-2011, 09:37 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Nobody's taken an expert approach (or any other) to your question here, so this amateur will give it a go.

"Knowing" socket programming is similar to "knowing" English. You'll never know everything, and what you know depends on what you need or want.

I had never heard of serialization (in a network context) or thrift (in a network context) until you mentioned them. But I've been doing network programming for years.

Anyway, here's where my wandering has led me:

Even in the ordinary area of TCP reading and writing, it's a good idea to get some experience doing that completely asynchronously (O_NONBLOCK), including the connect()s and accept()s, in a select() loop. (Or maybe poll()).

Also, if you want a thorough basis for your knowledge, get (and read) these books by W. Richard Stevens of happy memory:
  1. UNIX Network Programming, volumes 1, 2, 3.
  2. TCP/IP Illustrated, volumes 1, 2, 3.
Ok, who else has some ideas?
 
2 members found this post helpful.
Old 05-08-2011, 02:16 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

The responses you got over on StackOverflow (a fine forum, by the way) ... sounds like they must have been smoking crack or something

It's kind of like if you asked "What should I learn about programming?", and they replied "You need to study up on closures and start using Haskell". C'mon!

Here's a MUCH better answer ... to a very SIMILAR question ... on the SAME forum:

http://stackoverflow.com/questions/4...implementation

I completely agree with wje_lq's suggestion - I have a well-worn copy of Stevens' "Unix Network Programming, vol 1" myself. You can't go wrong with any of his books. They're incredibly lucid - and they delve into great depth. Highly recommended!

Another suggestion is Beej's Guide to Network Programming:

http://beej.us/guide/bgnet/

And if you really wanted to knock yourself out, you could do worse than study the source code for something like:

a) the Linux kernel's TCP/IP stack
<= There are also several books available to help explain the kernel source

b) Apache web server

And finally, the "gospel" for TCP/IP (and hence for knowledgeably programming sockets) are the RFC's:

http://www.faqs.org/rfcs/

'Hope that helps .. PSM
 
2 members found this post helpful.
Old 05-13-2011, 01:37 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Thanks to both of you, for your links and books. The purpose of this question was to know where should I get started from.

My thread of StackOverflow may help someone else: http://programmers.stackexchange.com...et-programming

The second reply there, was the only reply when I created this thread.
 
Old 05-13-2011, 08:35 AM   #5
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Anisha Kaul View Post
Any other inputs are welcome.
Although I'm not a network programmer, IMO you should at least be aware of endianness. However, Qt provides helper classes for that (QDataStream). What else you would need to know depends on your task. It is possible to write network application without knowing all the internals.
 
1 members found this post helpful.
Old 05-13-2011, 12:42 PM   #6
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
I'd like to emphasize understanding the different ways socket communications can be used. Not just non-blocking I/O, but handling the SIGURG (out-of-band data arrived) or SIGPIPE (stream socket breaks) signals via fcntl() or ioctl(), too. How and why using send() or sendto() with MSG_MORE flag will often increase thoroughput. How to send out-of-band data using send() or sendto() with MSG_OOB. What are the pitfalls (failure modes, typical problems, risks) in each use case.

Understanding the methods and concepts is much more important than remembering any details. I make a point of not trying to memorize e.g. the flags to sendto(); when you write code, it takes only a few seconds to check the function in a reference, and to make sure you have the correct syntax. A good counterexample is the memset() call: the first parameter is the pointer, but is the size or the value the second parameter? Size is last, and memset(,,0) does nothing; still, memset(,,0) is regularly seen in C sources, including the Linux kernel.

You'll see a lot of interesting methods if you check how for example Apache and cgid or fastcgi communicate, or how MySQL or PostgreSQL do local connections.

As they say, if the only tool you have is a hammer, all problems look like nails. Having a wide and varied base to draw upon will help you find better solutions.
 
1 members found this post helpful.
Old 05-20-2011, 07:32 AM   #7
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Thank you SigTerm and Nominal Animal for the helpful posts.

Following are the examples of the kinds of things which I need to understand:
1. QNetworkSession:

How that class works is explained in the Qt docs, but I am not clear with what is meant by a network session and how is it set in general?

2. QNetworkConfiguration:

The description says:
In most cases a single access point configuration can be mapped to one network interface. However a single network interface may not always map to only one access point configuration. Multiple configurations for the same network device may enable multiple access points.

<sigh> These basic concepts are not clear to me Any brilliant and not too lengthy book for clearing off these basics? Networks was never my favourite subject. Perhaps never paid attention to it!

The beej's socket programming book deals with socket API descriptions, mostly.
 
Old 05-20-2011, 08:04 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
Here's another thought ...

No matter what it is that you're doing, it is extremely likely that you'll be solving a problem that has already been solved before, and that someone over the years has developed a higher-level protocol, based on sockets (perhaps), for doing it. They've already solved the protocol-problems (that are by definition built-upon the socket-or whatever-it-is "transport" layer), such that, if your due-diligence enables you to find it, you can utilize it "off the shelf." Before diving too far into a new implementation (of anything at all), "look well, before you leap."
 
Old 05-20-2011, 07:38 PM   #9
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
I prefer to work with the back-end and low-level stuff. In fact, I normally stay very far away from frameworks, and much prefer modular libraries instead.

That said, I thought the BearerCloud and BearerMonitor examples illustrate the ideas and concepts pretty well, even if the names are atrocious, stupid buzzwords glued together. Yuk.

Here's my understanding:

The QNetworkSession class provides a way for a Qt application to choose how it connects to the network. The details are specified in a QNetworkConfiguration object (supplied to the QNetworkSession constructor).

When your application calls QNetworkSession::open(), it essentially tells the OS that this is the way your application wishes to connect to the network. If successful, that call opens a new network session. So, Qt calls the network connectivity configuration, and all associated network connections, a network session.

The OS uses that information to keep track of which interfaces it should keep available. When the last session on an interface closes, the OS can then for example power down the interface. That is also why your application needs to open a network session before making network connections: the network connection is likely unavailable otherwise.

For example, if your application runs on a device that can connect to the net via both GPRS and WLAN, it can use QNetworkConfigurationManager class to monitor connectivity and receive notifications of connectivity changes. The application can then use the QNetworkSession class to select which ones it wishes to use for its network connections.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Programming mselaledi Linux - Newbie 1 09-02-2010 03:29 PM
syatem programming concepts xyz Programming 2 09-25-2009 03:42 AM
socket programming???? harbir Linux - Networking 2 07-05-2004 02:52 AM
Where can I learn more advanced programming concepts? OrganicX Programming 8 03-01-2003 08:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration