C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2003, 05:18 PM
spade99 spade99 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 11 spade99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Linux socket programming

Where can I find a good introduction to socket programming?

Reply With Quote
  #2  
Old January 23rd, 2003, 06:09 PM
jonsagara's Avatar
jonsagara jonsagara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: USA
Posts: 286 jonsagara User rank is Private First Class (20 - 50 Reputation Level)jonsagara User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 23 sec
Reputation Power: 8
http://docs.sun.com/db/doc/802-5886...=sockets&a=view

... though this is for Sun, it should be largely the same ...
__________________
Jon Sagara

"Me fail English? That's unpossible!"

Reply With Quote
  #3  
Old January 23rd, 2003, 06:20 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 511 Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level)Analyser User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 47 m 19 sec
Reputation Power: 37
Send a message via ICQ to Analyser
__________________
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/

Reply With Quote
  #4  
Old January 23rd, 2003, 07:38 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,313 Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 4 Days 4 h 23 m 47 sec
Reputation Power: 2529
Try out Unix Network Programming by W. Richard Stevens. This is probably the Bible of Network Programming and reading just Volume I will probably make you more knowledgable about sockets than most other books. It covers socket programming very comprehensively and practically all network programming books and articles always have this book in their list of references.

Reply With Quote
  #5  
Old January 24th, 2003, 10:25 AM
spade99 spade99 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 11 spade99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Linux socket programming

Thanks people,


I have been trying to understand the info on the web about sockets, threading and multiplexing. I find that jumping around from site to site can be too much information to take in at once.

I will visit the links and buy the book...

Thanks again.

Reply With Quote
  #6  
Old January 31st, 2003, 04:11 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 4,438 dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 5 h 57 m 58 sec
Reputation Power: 1101
Stevens' "Unix Network Programming" is indeed considered the "Bible of Network Programming", but if you are looking for an introduction then maybe a "tract" would be more useful at this point. Stevens may prove to be too comprehensive for you right now.

As an introduction, I would recommend "TCP/IP Sockets in C: Practical Guide for Programmers" by Michael J. Donahoo and Kenneth L. Calvert, Morgan Kaufmann Publishers, 2001 (ISBN 1-55860-826-5). It's 110 pages long and costs $15. OTOH, "Unix Network Programming" comes in two volumes at about $70 each, $140 total -- not even Amazon.com offers a discount -- and appears to cover all of POSIX interprocess communication as well as a non-sockets API called XTI. The previous edition of "TCP/IP Sockets in C: Practical Guide for Programmers" was called "The Pocket Guide to TCP/IP Sockets: C Version" (ISBN 1-55860-686-6) and is still out in the bookstores and covers pretty much the same material.

I started out studying and researching all I could and found myself in "analysis paralysis", afraid to try to write a sockets program until I understood it all. "The Pocket Guide to TCP/IP Sockets: C Version" got me coding almost immediately. So far in my spare time, I've written time clients and servers, an embedded telnet client, and a "man in the middle" utility that I used to capture and analyze telnet traffic (for writing the embedded client). Their books (they've also written one for Java) are a good introduction to sockets programming that can get you started fast. It also has a good API reference section in back which I keep in my Palm for reference.

You should also visit their web sites: http://cs.baylor.edu/~donahoo/PocketSocket/ and http://cs.baylor.edu/~donahoo/practical/CSockets/ for the source code and for information on writing Winsock applications. It turns out that a Unix sockets app can be converted to Windows with just a few minor changes (a common task for me, since I'm the only one at work with a Linux box); the process is described in a short document on their site, "Transitioning from UNIX to Windows Socket Programming" by Paul O'Steen (http://cs.baylor.edu/~donahoo/pract...dowsSockets.pdf ).

Then after you have gotten a good introductory start, Stevens would be more useful.


Also, since you named this thread "Linux Socket Programming", you might want to look at Warren Gay's "Linux Socket Programming by Example" (ISBN 0-7897-2241-0). It starts with the basics and moves on to more advanced topics, like . For example, I was able to verify my design for a broadcast client application, which I have not seen covered elsewhere.

Also, you might want to check out Analyser's "shameless plug". I found Beej's Guide to be helpful.


BTW, sockets are the easy part. Working out the interaction between servers and clients are slight more difficult. The difficult part is researching the application-layer protocols, like telnet. For that, you will need to start digging through the Requests for Comment (RFCs).

Good luck and have fun!

Reply With Quote
  #7  
Old September 15th, 2009, 02:13 AM
kwkhoo kwkhoo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 3 kwkhoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 11 sec
Reputation Power: 0
Linux Socket UDP C Program

Hi,
I am trying to develop an UDP socket C program in SUSE Linux. I have found and downloaded the UDP C program from Beej's Guide to Network Programming. I have compiled both the talker.c and listener.c in the SUSE Linux. Run the talker program in my MAC machine to send 14 bytes of data. And run the listener program in the SUSE Linux. However, I am not able to receive anything in my Linux machine. When doing the reverse, running the talker in the Linux machine; and running listener in the MAC machine, I can receive in my MAC machine. The code for the listener.c is shown below. Can someone tell me what is going wrong? I have been trying very hard and tried to find solution in the internet but still no clue. Really appreciate if someone can tell me what I have done wrong.
Thanks.

/////////////////////////////////////////////////////
/*
** listener.c -- a datagram sockets "server" demo
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#define MYPORT "4950" // the port users will be connecting to

#define MAXBUFLEN 100

// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}

return &(((struct sockaddr_in6*)sa)->sin6_addr);
}

int main(void)
{
int sockfd;
struct addrinfo hints, *servinfo, *p;
int rv;
int numbytes;
struct sockaddr_storage their_addr;
char buf[MAXBUFLEN];
size_t addr_len;
char s[INET6_ADDRSTRLEN];

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; // use my IP

if ((rv = getaddrinfo(NULL, MYPORT, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}

// loop through all the results and bind to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
perror("listener: socket");
continue;
}

if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
perror("listener: bind");
continue;
}

break;
}

if (p == NULL) {
fprintf(stderr, "listener: failed to bind socket\n");
return 2;
}

freeaddrinfo(servinfo);

printf("listener: waiting to recvfrom...\n");

addr_len = sizeof their_addr;
if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
(struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}

printf("listener: got packet from %s\n",
inet_ntop(their_addr.ss_family,
get_in_addr((struct sockaddr *)&their_addr),
s, sizeof s));
printf("listener: packet is %d bytes long\n", numbytes);
buf[numbytes] = '\0';
printf("listener: packet contains \"%s\"\n", buf);

close(sockfd);

return 0;
}
Comments on this post
jwdonahue disagrees: Start your own thread. Don't dreadge up a six year old thread to pose a new problem.

Reply With Quote
  #8  
Old September 15th, 2009, 02:37 AM
jwdonahue's Avatar
jwdonahue jwdonahue is offline
Bellevue WA, USA
Click here for more information.
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 2,377 jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level)jwdonahue User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 17 m 57 sec
Reputation Power: 563
Firstread this (really, follow the link).

DO NOT BOTHER TO RESPOND TO THIS THREAD.

Check that your local firewalls aren't preventing communications in one direction or the other. If that isn't the problem, start your own thread.
__________________
My worst nightmare was a pointless infinite loop.
Work in progress; don't poke the curmudgeon!
http://www.odonahue.com/

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Linux socket programming


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT