LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 06-11-2009, 02:54 AM   #1
TALR
LQ Newbie
 
Registered: Jun 2009
Location: America
Distribution: Ubuntu, Puppy Linux, and Mandriva
Posts: 4

Rep: Reputation: 0
Unhappy Programming - C++ Sockets: Is all just C?


Hello LQ community!

I have been programming in C++ for a short period of time now, under Ubuntu, with the g++ compiler.

I recently tried starting network (sockets) programming and I am finding the subject very obscure and confusing. All the tutorials, references, and examples I come across for C++ programming always seem to have plain C code, with hardly, if any C++ (such as using the <iostream> header, instead of C's, <stdio.h>). I am finding it difficult to implement C code into C++ code, and because of this, I am not sure where to start, and I surely don't want to start on the wrong foot.

Now, I am not asking you to answer every question about sockets programming known to man, but just this. Is there a specific library/method of programming for writing sockets in actual C++ code, or will I just have to work with writing mixed C/C++ code (or possibly just C)? I am very set-in to the way of coding habits/structure/syntax for C++, and I just want to know if what information I am finding is just the way it is - meaning I will have to mix code, or just code in C - or is there something I'm missing. I want to code in C++ because in terms of buffer overflows and other unnoticed syntactical errors that can be exploited, C++ sounds to be a lot safer.

Please, if you could, also post helpful resources on this subject, or the subject of sockets (done in C++).

Note, though, that I've already looked at Rob Tougher's tutorial, and I cannot seem to get it to compile. If you can, any help with this is also appreciated, as it is also a relevant answer to this question.

Thank you
 
Old 06-11-2009, 03:18 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I'm not a C++ coder, so can not really help you. But isn't it a matter of simply using the standard socket functions in your class? And everytime you encounter something that requires standard C stuff (e.g. printf), replace it with the C++ counterpart?

If you need help with last part of your question, please post relevant code and compile errors ("can't seem to get it to compile" does not give us much to go on).

There is a dedicated programming section here at LQ; you probably have more chance in there.

Use the report button at the bottom of your post if you want a moderator to move your thread.

WimS
 
Old 06-11-2009, 01:32 PM   #3
TALR
LQ Newbie
 
Registered: Jun 2009
Location: America
Distribution: Ubuntu, Puppy Linux, and Mandriva
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks, I was looking for the programming forum but just couldn't find it . I will try to get someone to move it over there for me.
 
Old 06-11-2009, 01:51 PM   #4
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 25
Quote:
Originally Posted by TALR View Post
Note, though, that I've already looked at Rob Tougher's tutorial
Have you looked through Socket.h and Socket.cpp?
 
Old 06-11-2009, 02:25 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 06-11-2009, 02:48 PM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
how about?

boost
 
Old 06-11-2009, 03:14 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Or Qt ?
 
Old 06-12-2009, 01:58 AM   #8
TALR
LQ Newbie
 
Registered: Jun 2009
Location: America
Distribution: Ubuntu, Puppy Linux, and Mandriva
Posts: 4

Original Poster
Rep: Reputation: 0
Lightbulb

Thanks very much guys!

(bigearsbilly) -> I really like the look of boost, and
(Tinkster) -> Thanks for showing me that, as I didn't know
that the qt library also had support for sockets. Thanks
very much for enlightening me, as I have proved I'm a total
"noob" in C++
 
Old 06-12-2009, 03:37 AM   #9
giftlftr_23
Member
 
Registered: Oct 2008
Location: I live where I'm currently standing on
Distribution: fedora, opensuse
Posts: 34

Rep: Reputation: 17
To use a c standard library just prefix them with c and remove the .h.
e.g.
Code:
#include <stdio.h>
to
Code:
#include <cstdio>
and prefix all the c standard functions with double colon..
e.g.
Code:
 
printf("...");
scanf("%d", ...);
to
Code:
::printf("...");
::scanf("%d", ...);

Regarding the socket library try Qt, as what Tinkster said. It has almost complete networking API. Or try this C++ Sockets Library http://www.alhem.net/Sockets/
 
Old 06-12-2009, 02:26 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 452Reputation: 452Reputation: 452Reputation: 452Reputation: 452
Probably also in wxWidgets: www.wxwidgets.org .
 
Old 06-12-2009, 09:32 PM   #11
TALR
LQ Newbie
 
Registered: Jun 2009
Location: America
Distribution: Ubuntu, Puppy Linux, and Mandriva
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you all

I think I'm going to go with the QT library, since I think I already have that installed;

Does anyone know any good documentation and/or reference documents for this? (preferably in HTML or PDF, but whatever works)
 
Old 06-12-2009, 09:46 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Qt comes with a complete set of HTML docu ... check the package
content of Qt.


Cheers,
Tink
 
Old 06-13-2009, 03:42 AM   #13
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
you may already have boost installed.
(it's on my BSD for instance)

I think it's pretty much a de-facto standard in
industry for C++
so it's probably worth knowing.
 
  


Reply

Tags
c++, network, programming, sockets


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Programming timeout with sockets simasimon Programming 6 05-03-2008 12:16 AM
is sockets programming my only way? nesta Programming 1 03-23-2007 10:37 AM
Sockets Programming pink_lady Programming 4 05-31-2006 07:56 AM
Question about Sockets Programming sibtay Programming 2 09-24-2004 05:04 PM
Sockets Programming-Getting Started funkymunky Programming 3 01-09-2004 12:51 PM


All times are GMT -5. The time now is 03:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration