-(void) createSocket
{
int sockfd;
struct sockaddr_in servaddr;
char sendline[] = "hello world";
char addr[] = “10.0.0.1";
sockfd=socket(AF_INET,SOCK_DGRAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr=inet_addr(addr);
servaddr.sin_port=htons(5527);
sendto(sockfd,sendline,strlen(sendline),0,
(struct sockaddr *)&servaddr,sizeof(servaddr));
// Create CFSocket
const CFSocketContext context = { 0, (__bridge void *) (self), NULL, NULL, NULL };
CFSocketRef _cfSocket;
_cfSocket = CFSocketCreateWithNative(NULL, sockfd, kCFSocketReadCallBack, kCFSocketReadCallBack, &context);
}
Hi,
I am new to objective c. As a part of a simple project I needed to build a UDP based client in objective c.
I have managed to create C based socket and get a CFSocket reference from it.
The place where I am stuck is:
Get a CFReadStreamRef and CFWriteStreamRef for the CFSocket that I have created.
is there a way that I can do that? I read the documentation for CFStream at apple but I couldn’t figure out much there. Any suggestions would be great.
Thanks
Aucun commentaire:
Enregistrer un commentaire