I've looked over the Classes that seem relevant but it is not clear that there is a Class equivalent to Pipe that is for TCP/UDP sockets. The Socket class description seems to not just do what you need to create and bind a port and set up listening. At the moment I've implemented this in straight unix networking primitives... but it would be nice if I Socket were really the same API as Pipe.
我已经查看了似乎相关的类,但不清楚是否有一个类似于Pipe的类用于TCP / UDP套接字。 Socket类描述似乎不仅仅是你需要创建和绑定端口并设置监听。目前我已经在直接的unix网络原语中实现了这一点......但如果我的Socket与Pipe真的是同一个API那就太好了。
How do others deal with this? Am I mistaken in what Socket does?
别人怎么处理这个?我错了Socket的作用吗?
This is a case where I don't want complexity, just a standard OO cover to standard IP networking.
在这种情况下,我不需要复杂性,只是标准IP网络的标准OO封面。
1 个解决方案
#1
1
I haven't used GNUstep in a while, so this is based off of Apple's libraries, and you will need to make sure there are no differences.
我有一段时间没有使用过GNUstep,所以这是基于Apple的库,你需要确保没有差异。
TCP connections can be created using a class method on NSStream, which returns an input stream and output stream for communication.
可以使用NSStream上的类方法创建TCP连接,该方法返回输入流和输出流以进行通信。
NSHost *host = ...;
NSUInteger port = ...;
NSInputStream *input;
NSOutputStream *output;
[NSStream getStreamsToHost:host port:port inputStream:&input
outputStream:&output];
For other connections, you can create the connection using the standard Unix API, then create a NSFileHandle to wrap the file descriptor.
对于其他连接,您可以使用标准Unix API创建连接,然后创建NSFileHandle以包装文件描述符。
int fd = socket(...);
NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES];
#1
1
I haven't used GNUstep in a while, so this is based off of Apple's libraries, and you will need to make sure there are no differences.
我有一段时间没有使用过GNUstep,所以这是基于Apple的库,你需要确保没有差异。
TCP connections can be created using a class method on NSStream, which returns an input stream and output stream for communication.
可以使用NSStream上的类方法创建TCP连接,该方法返回输入流和输出流以进行通信。
NSHost *host = ...;
NSUInteger port = ...;
NSInputStream *input;
NSOutputStream *output;
[NSStream getStreamsToHost:host port:port inputStream:&input
outputStream:&output];
For other connections, you can create the connection using the standard Unix API, then create a NSFileHandle to wrap the file descriptor.
对于其他连接,您可以使用标准Unix API创建连接,然后创建NSFileHandle以包装文件描述符。
int fd = socket(...);
NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES];