Currently, I’m trying to get the lib working in my project, but with no results. I copied its source classes and objective-c wrapper classes (ZMQContext, ZMQSocket) to my project and was able to build it successfully. However, I’m getting “resource temporary is unavailable” when trying to send a request to a server. Here’s my code:
ZMQContext *context = [[ZMQContext alloc] initWithIOThreads:1];
ZMQSocket *socket =[context socketWithType:ZMQ_REQ];
BOOL success = [socket connectToEndpoint:@"tcp://X.X.X.X:X"];
if (success){
NSLog(@"connected to server");
}
NSData *data = [self RequestData];
success = [socket sendData:data withFlags:0];
if (success){
NSLog(@"Data sent to server");
}
Somehow, “connectToEndpoint” call is successful, however i can’t’ say the same about send. I can assure the host is reachable via the port, because server side socket communication version is already in production state. Just curious, has anyone zeromq working for iOS?
UPDATE: I have also posted the same question as an issue to github project here and got the answer: “You only show one side of the code here. If the other side is not running ZMQ, you will naturally be unable to exchange messages.”. This means we cannot use ZMQ as a client only (to existing server that is implemented with other lib or custom solution). If it’s true then ZMQ is very limited.
I will clarify a little bit for those who also had stumbled upon the application of ZeroMQ, as there’s a lack of fundamental info about how the stuff works. In my situation, I have existing server that accepts connections via socket so the data can be send and received. All the data that goes through sockets, goes through tcp packets (at low level) but you don’t have to worry about how data is transferred in tcp packets. With sockets, everything you need know is that you need to construct a packet of bytes and send it to the server. The server also will return you a packet of bytes and it’s your responsibility how you will interpret those bytes. For example, if I want to send 2 bytes of data to the server, for example 1 byte of value 1 and another byte of value 2, I will need to construct and send 00000001 00000010 (without space 🙂 ). The server will also return me some bytes.
The thing is with raw socket communication, you have manually to implement a protocol – the rules. Why? Because you have manually to check received packet if it has correct length, correct data. The server and client must both agree on what is the data format, which byte is status, which bytes represent packet length and which bytes represent data. For example imagine a server is sending you raw bytes:
10001000 10010111 01101001 01111110 01110110 11100001
Both, client and server need to know what every byte means. So, in my situation, the server already has it’s own parser and the rules (it might be named as custom protocol) about what sequence of the bytes should come. For example, 1 byte is the request command, 4 bytes is the packet size, 1 byte is the status of request and the rest bytes are the data. When you are communicating with servers using higher protocols like HTTP, all the stuff is done for free, you just push or grab the data and that’s it. Also, the similar is with ZeroMQ as it already has its own parsing rules, so you just push and grab the data, but as mentioned before, both client and server need to use that lib.
When I was posting the question, I was looking for some lib that facilitates socket communication, but does not has it own the protocol. Currently, I’m trying to use AsyncSocket.