Frage

I am working on writing a simple Redis client application in Objective-C. In order to communicate with Redis on my server I need to SSH into the server and then open a TCP socket to send data back and forth. I am trying to follow an example from libssh2.org, direct_tcpip.c and I have gotten it to work well. I can run the code, and it will say:

Waiting for TCP connection on... 0.0.0.0:6379

So I then try to communicate with it using telnet:

telnet 0.0.0.0 6379

I can successfully connect and interact with Redis this way, YES!

Now the next step is for me to be able to programmatically talk to the server and send it commands from the UI of my app, but the program gets blocked when I call accept() and is stuck waiting for a connection to come in. That's a problem because I need to programmatically connect TO it and I can't seem to figure out how to do that.

I tried calling libssh2_session_set_blocking(session, 0); before accept(), but that didn't seem to change anything.

My goal is to set up the forwarding so that my app can communicate with a remote Redis server as easily as possible and I am totally new to socket programming. I need an SSH tunnel because Redis does not have built-in security and it is recommended that you communicate with it internally.

Thank you to anyone who can point me in the right direction!

War es hilfreich?

Lösung

The comment posted by @Danack solved the problem for me. I am using a background thread to do the listening and now I am no longer blocked and connecting just fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top