I am using following code in my App
but I am getting error when I am setting ip address like 192.168.0.1(in hexadecimal form)
in place of INADDR_ANY/0x7f000001(127.0.0.1).
BAction)createSocket:(id)sender {
CFSocketContext CTX = {0, "this is server", NULL, NULL, NULL};
tcpServer = CFSocketCreate(NULL,0, 0, 0,kCFSocketAcceptCallBack, 0, &CTX);
if (tcpServer == NULL)
NSLog(@"server isn't created");
else
NSLog(@"sever is successfully created");
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(2048);
addr.sin_addr.s_addr = htonl(0x7f000001);
NSData *address = [ NSData dataWithBytes: &addr length: sizeof(addr) ];
if (CFSocketSetAddress(tcpServer, (__bridge CFDataRef) address) != kCFSocketSuccess) {
NSLog(@"socket address not set");
}
else
{
NSLog(@"socket address is successfully added");
}
Can I add other ip address or any restriction to use other ip?
If we can than how?
I would like to use other ip because I am using three iphone to connect each other.
Your local IP address isn't 192.168.0.1. That's your router address. The bind-address has to be an IP address of an NIC in your local host, or INADDR_ANY, or 127.0.0.1.