Socket "bind" isn't working for me.
Socket "bind" isn't working for me.
- Subject: Socket "bind" isn't working for me.
- From: John Draper <email@hidden>
- Date: Sat, 23 Apr 2005 00:31:48 -0700
Hi,
Can someone please tell me what I might be doing wrong?
Desired conditions....
I have two remote hosts I want to communicate with by using the UDP
protocol. One host knows a list of other hosts. Looks something like
this.
Main Host (server)
client1
client2
<etc>
client1 and client2 may be behind a NAT. Main host knows both, so
client1 will
ask to be connected to client2. Since Mail Host knows both, it initiates
connections to both, once this happens, the connections are passed from
client1 to client2 and vice versa.
client1 will ask Main Host for IP/Port of client2. Client1 will use
only ONE socket
to communicate with Main Host and client2. "sendto" will be used to
send to
either remote host, depending on circumstances. So I'm going to want to not
only specify buffer and size, but also IP and port.
I want to be able to switch from one IP/Port to another. I think I can
either use
"bind" for that, and use "send", OR I use "sendto" and specify the
IP/Port.
I'm not sure which one to use. So far, neither works of course. So my
approach is flawed, or something is seriously wrong with the EDCommon code
code I'm using.
I have included one of the methods used in the EDCommon framework which
I presume would allow me to switch ip/ports.
You don't need to be familiar with EDCommon framework, because it uses the
UNIX style of Socket API's, and listed below, the code is quite obvious.
- (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)];
}
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.
Can someone explain how I can examine this "errno" using "gdb"?
Has anyone else reported problems like this? I already scanned the
archives,
and didn't see anyone post a similar problem.
John
_______________________________________________
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