블로그 이미지
Sunny's

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

'TCP'에 해당되는 글 1

  1. 2010.07.01 iPhone TCP Socket Sample Function
2010. 7. 1. 17:43 IPhone

from iPhone Programming 2008/11/27 14:47

아이폰에서 TCP 소켓 메세지를 보내는 샘플 예제
삽질했네...ㄷㄷㄷ


헤더파일 추가

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

CFSocketRef socket;

socket = CFSocketCreate(kCFAllocatorDefault,PF_INET,SOCK_STREAM,IPPROTO_TCP,0,NULL,NULL);
CFDataRef address, data;
struct sockaddr_in sin;

char message[] = "Hello Socket;

            

memset(&sin, 0, sizeof(sin));

sin.sin_len = sizeof(sin);

sin.sin_family = AF_INET;

sin.sin_port = htons(7258); //port

sin.sin_addr.s_addr = inet_addr("ip address");

            

address = CFDataCreate(NULL,(unsigned char*)&sin,sizeof(sin));

data = CFDataCreate(NULL,(unsigned char*)message,strlen(message));

            

CFSocketConnectToAddress(socket,address,0);

CFSocketSendData(socket,NULL,data,strlen(message));

CFRelease(address);

CFRelease(data);

CFRelease(socket);

posted by Sunny's
prev 1 next