connect() returns Refused Connection Error
connect() returns Refused Connection Error
- Subject: connect() returns Refused Connection Error
- From: "Jordan Evans" <email@hidden>
- Date: Thu, 27 Jul 2006 08:35:52 -0700
I'm trying to get two applications to connect to each other's
NSNetService of the same type. I'm trying to set it up so that when
AppA connects to AppB's service, AppB immediately connects to AppA's
service. AppA connects fine, I get no connection error. But, when
AppB try's to immediately connect to AppA's service, I get a
"connection refused" error.
1. Each App's service is published and watches in the background for
connections.
2. When a connection occurs, a -subscriptionNotification: is sent.
3. The -subscriptionNotification: implemetation is this:
- (void)subscriptionNotification:(NSNotification *)notification
{
NSLog(@"Subscription notification.");
// Retrieve the remote file handle.
[subscriberSockets addObject:[[notification userInfo]
objectForKey:NSFileHandleNotificationFileHandleItem]];
// Create structure for getting remote address.
struct sockaddr addr;
int namelen = sizeof(struct sockaddr);
struct sockaddr *addressPtr;
// Get the file descriptor of the remote socket.
int fh = [[subscriberSockets lastObject] fileDescriptor];
// Get the address of the remote peer.
if(getpeername(fh, &addr, &namelen));
perror( "getpeername" );
// No error here.
// Assign pointer to remote address, so pointer can be passed in
connect() function.
addressPtr = &addr;
// Debugger proves address is identical.
// Create a socket for connecting to the remote socket.
int s = socket( AF_INET, SOCK_STREAM, 0 );
// Connect the remote address to the new socket.
if( connect( s, addressPtr, namelen ) )
perror( "connect" );
// Connection error here: "connect: Connection refused"
...
}
Any idea why I am refused a connection to the peer?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden