0

I try to new a socket in watchos platform, and it always failure, the same code run in ios platform,and success,what's wrong? here are some code:

#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>

int clientsocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in serverAddr;
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = inet_addr("192.168.124.52");
serverAddr.sin_port = htons(45678);
int connectResult = connect(clientsocket, (const struct sockaddr *)&serverAddr,sizeof(serverAddr));
NSLog(@"connect res : %d",connectResult);

next I try $nc -lk 45678 in terminal,the connectResult always return -1, and the same code run in ios platform it's ok.

vicki
  • 402
  • 2
  • 8
jchao
  • 1
  • 2

0 Answers0