자료2009. 12. 18. 18:00

아주 기본적인 기능만 지원하는 BSD소켓 래퍼이다.


가장 예제가 많이 있던 NSStream을 사용하려고 했는데 NSHost가 지원이 중단됐다고 해서 골머리를 앓다가;

CFSocket을 쓰는 방법도 있지만 뭔가 Cocoa랑 섞어 쓰기 이상하고 그래서; 그냥 실험3때 쓰던 소스를 좀 고쳐서 만들었다.

예제:

char text[1024]; int len;
Socket *socket=[Socket new];
[socket connect:@"www.google.co.kr" port:80];
[socket sendString:@"HEAD / HTTP/1.0\nHost:www.google.co.kr\n\n"];   
[socket receive:text length:1024];
text[len]='\0';
puts(text);

결과:

HTTP/1.0 200 OK
Date: Fri, 18 Dec 2009 08:59:17 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: text/html; charset=EUC-KR
Set-Cookie: PREF=ID=a702d3cb504f88b4:NW=1:TM=1261126757:LM=1261126757:S=ziCgYtdHL9lFqrmH; expires=Sun, 18-Dec-2011 08:59:17 GMT; path=/; domain=.google.co.kr
Server: igfe
X-XSS-Protection: 0

Posted by jongwook