LinuxQuestions.org
Visit Jeremy's Blog.
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 06-24-2005, 08:23 AM   #1
mdimanna
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Rep: Reputation: 0
Question Socket error on Connect


I am an experienced socket programmer in older versions of Unix and am now writing a socket based server in Linux. I have written what one would assume to be a hellow world server (socket based) in Linux, but my client always errors out on connect with perror returning "Connection refused". I have turned off the firewall but to no avail. I cannot find anywhere on the web or man pages about this error. Any thoughts???
 
Old 06-24-2005, 09:23 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
It's hard to tell without seeing some code, but I'd suggest checking the return value of all the socket operations to make sure there's no errors.

The order of the socket operations should go:
socket()
** Probably wise to use setsockopt() to set the SO_REUSEADDR flag here **
bind()
listen()
accept()

I'd also suggest maybe just using telnet to try connecting to the server to make sure that side of it works before trying to connect with your client.

Last edited by itsme86; 06-24-2005 at 09:24 AM.
 
Old 06-24-2005, 10:28 AM   #3
mdimanna
LQ Newbie
 
Registered: Jun 2005
Posts: 3

Original Poster
Rep: Reputation: 0
DUH. Thanks for the advice

As I was adding code to check return values on bind, I realized I was using htons on the long parameter for server_addr.sin_addr.s_addr. Thanks for the slap on the head. Sorry.
 
  


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
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
error: Can't connect to local MySQL server through socket J0sep Red Hat 20 07-13-2011 09:32 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 07:28 PM
connect: socket operation on non-socket bit7 Linux - Networking 0 02-18-2003 05:08 PM

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

All times are GMT -5. The time now is 11:20 AM.

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