Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple c++ socket server help

Status
Not open for further replies.

clax99

Programmer
Oct 29, 2001
23
US
HELP!! I am wondering what is the simplest way to open a socket and listen to a port with C++ for very simple data transmissions. I can do it easily in Java with the java.net.ServerSocket class. However, I've only found examples online that require numerous, random, .h includes of files I've never heard of. Any help would be greatly appreciated.
 
Search Google for "Beej's Guide to Network Programming". This is a very good intro to socket programming for Unix/Linux.
 
You need the following libraries:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

and you use the following system calls:

socket() -> bind() -> listen() -> accept()

This is the order in which they will need to be used. I suggest that you look up the syntax for these calls, and let me know if you have any joy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top