你知道一些很好的教程吗,教你如何建立一个简单的TCP套接字连接到ip,并向其发送JSON?
我很沮丧,因为我找不到容易实现的东西(我还是个新手)。
谢谢大家!
我刚刚学习了raywenderlich教程:
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
并对流的启动进行了一点调整:
- (void) initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"xx.xxx.xxx.xxx", 1256, &readStream, &writeStream);
inputStream = objc_unretainedObject(readStream);
outputStream = objc_unretainedObject(writeStream);
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}