Scott, Marty,

I did run my program through debug to verify that I am using same socket 
descriptor throughout my program.  I am not closing the socket before I 
send.  The connection stays alive until I do a send( ).  As soon as I do a 
send, I see the connection drop in NETSTAT.  I am not checking for errors 
after the connect, as Marty suggested. I will add that to my code and run 
it through debug again. 

This is written in RPG and is largely based on Scott's code.  Let me do 
some more testing and I will let you know how that goes.

Thanks. 

Mark Garton





message: 1
date: Wed, 9 Aug 2006 12:48:56 -0500 (CDT)
from: Scott Klement <midrange-l@xxxxxxxxxxxxxxxx>
subject: Re: Socket Descriptor Error


I am working on a project where I connect to an outside vendor using
sockets.  I am getting a EBADF - "Descriptor not valid" error when I try
to do a send.  The code that I am using works in other programs.

When you call the socket() API, it returns a number.  You then store that 
number into a variable and later pass it as a parameter to the send() API. 

Can you verify (by running your program in debug, etc) that the number you 

got from socket() is the exact same number you're passing to the send() 
API?

Are you sure the socket hasn't been closed?  If you close a socket, but 
then still try to send data with the send() API, you can get a BADF error.

Another cause that I've seen is when the remote host has disconnected, and 

your application has already been sent an error code in a previous API 
call (or in the background on a non-blocking, in progress call, like 
"connect" does).  Since it has already sent you an error telling you that 
the connection is dead, subsequent calls to the socket APIs can result in 
EBADF.


I verified that the socket descriptor is consistent in my program. I am 
not sure what else to check.  Any help would be greatly appreciated.

Unless this is actually a network error (which seems unlikely if other 
programs work) the problem is a bug in your code.  Since we haven't seen 
your code, it's difficult to provide any more specific help than an 
explanation of what might cause the error.






As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.