我想为iPhone实施一个Voip应用程序。
如何在使用套接字编程和流式传输的用户之间建立点对点连接。
任何可用的源代码。
答案 0 :(得分:1)
尝试GCDAsyncSocket https://github.com/robbiehanson/CocoaAsyncSocket
或者你也可以尝试一下 http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
答案 1 :(得分:0)
定义类属性:
NSInputStream *inputStream;
NSOutputStream *outputStream;
初始化你的溪流
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)kScannerIP, kScannerPort, &readStream, &writeStream);
inputStream = (__bridge NSInputStream *)readStream;
outputStream = (__bridge NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
实现委托方法来处理传入的数据:
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
switch (streamEvent) {
case NSStreamEventOpenCompleted:
break;
case NSStreamEventHasBytesAvailable:
break;
case NSStreamEventHasSpaceAvailable:
break;
case NSStreamEventErrorOccurred:
break;
case NSStreamEventEndEncountered:
break;
default:
NSLog(@"Unknown event");
}
}
最后关闭你的网络:
[inputStream close];
[outputStream close];
[inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
inputStream = nil;
outputStream = nil;
答案 2 :(得分:-2)
你不能;当你的设备的IP都发生变化时(两者都转移到不同的网络)会发生什么?