LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-01-2004, 11:19 AM   #1
PoorGuy
LQ Newbie
 
Registered: Nov 2004
Posts: 5

Rep: Reputation: 0
Fail to accept connection


I am writing a server-client program, normally the server can accept a client connection using accept(). But I want to see some data structure about the server so I add some code for printing the data structure (which is a 2D array with about hundred entry) before the server begins to create socket, bind , listen and accept.
The create, bind and listen goes all right but accept fail with errno set to EBADF. So what should I do to eliminate the error??? Thx in advance
 
Old 11-01-2004, 11:23 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You should pass accept() a valid socket.
 
Old 11-01-2004, 09:25 PM   #3
PoorGuy
LQ Newbie
 
Registered: Nov 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thx.
My code is like that
listen(listenSockFD, (other needed argument))
on return, listen() gives 0 (ie valid), and listenSockFD is 3 (this is the value I usually get) then
sessionFD = accept(listenSockFD, (other needed argument))
On return, sessionFD = -1 which mean failure
what can I do to ensure the file descriptor valid?
 
Old 11-01-2004, 09:51 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You should have something like: listenSockFD = socket(....)
 
Old 11-01-2004, 10:58 PM   #5
PoorGuy
LQ Newbie
 
Registered: Nov 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thx a lot
I have that but I was just lazy to include it in my last reply.
I'll give more details when I'm back home as the ftp server has been down
 
Old 11-02-2004, 10:40 AM   #6
PoorGuy
LQ Newbie
 
Registered: Nov 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Here is an extract from my code
listenSockFD = socket(AF_INET, SOCK_STREAM, 0); // usually 3 is returned
bind(listenSockFD, (struct sockaddr*)&serverAddr, sizeof(serverAddr)); //0 return
listen(listenSockFD, 10); // 0 return
sessionFD = accept(listenSockFD, (struct sockaddr*)&clientAddr, &clientLen);
// return -1, this is where error occur, with errno set to EBADF. Error only occurs if I print a 2D table before creating socket. If I do not print the 2D table, there won't be error

really need to help
thx a lot
 
Old 11-02-2004, 10:42 AM   #7
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Maybe the problem isn't in your socketing code then. Are you running out of bounds with your 2D array perhaps?
 
Old 11-04-2004, 09:10 AM   #8
PoorGuy
LQ Newbie
 
Registered: Nov 2004
Posts: 5

Original Poster
Rep: Reputation: 0
thx a lot~
i solve the problem after using bzero() on the address structure and buffer
 
  


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
Setup Linux to accept modem users connection longnam Linux - Hardware 1 04-07-2005 03:43 PM
My slackware to accept ftp connection rsumbeling Linux - Networking 5 11-15-2004 11:31 AM
Tightvnc auto accept connection? Hitman_sp Linux - Software 0 08-09-2004 10:12 AM
a program to listen+accept incomming connection+echo packets ? qwijibow Linux - Software 0 03-01-2004 09:10 PM
Internet connection problem. ISP won't accept user/pass duffboygrim Linux - General 1 12-23-2003 04:19 AM

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

All times are GMT -5. The time now is 05:29 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