Re: Socket "bind" isn't working for me.
Re: Socket "bind" isn't working for me.
- Subject: Re: Socket "bind" isn't working for me.
- From: Cameron Kerr <email@hidden>
- Date: Sun, 24 Apr 2005 01:05:49 +1200
On 23/04/2005, at 7:31 PM, John Draper wrote:
- (void)setLocalPort:(unsigned short)aPort andAddress:(NSString
*)addressString
{
struct sockaddr_in socketAddress;
memset(&socketAddress, 0, sizeof(struct sockaddr_in));
socketAddress.sin_family = AF_INET;
socketAddress.sin_addr = EDInAddrFromString(addressString);
socketAddress.sin_port = htons(aPort);
if(bind(EDSOCKETHANDLE, (struct sockaddr *)&socketAddress,
sizeof(socketAddress)) == -1)
[NSException raise:NSFileHandleOperationException
format:@"Binding of socket to port %d failed: %s", (int)aPort,
strerror(ED_ERRNO)];
}
The use of EDSOCKETHANDLE is probably wrong. I'm guessing it's a
constant. It should be what is returned from socket()
In My application, the "bind" fails and returns a -1. However,
I'm unable to read "errno" to determine just what the error is.
I looked for "errno", a standard global variable containing this
value, but I have no way to look at it, because the
"strerror(ED_ERRNO)" is also broken.
You need to #include <errno.h> in order to inspect the errno variable.
I HIGHLY recommend you get yourself a copy of Unix Network Programming,
Volume 1. You won't regret it for programming with the Sockets API. For
a good introduction to Sockets that is easy to read and understand, do
a search for 'Beej' on Google. It'll be the first hit.
--
Cameron Kerr
Telecommunications Teaching Fellow & SysAdmin
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden