This question already has answers here:
Where can I find a good tutorial on iPhone/Objective-C multithreading? [closed]
(5 answers)
Closed 9 years ago.
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!
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.
Related
This question already has an answer here:
Pass connected SSL Socket to another Process
(1 answer)
Closed 5 years ago.
The first process will receive and send some data (to complete the authentication) after accept a sslsocket, then send the sslsocket to another process.
I know that multiprocessing.reduction.send_handle can send socket, but it didn't work with sslsocket.
Please help.
This is not possible.
SSL sockets in Python are implemented using OpenSSL. For each SSL socket in python there is a user space state managed by OpenSSL. Transferring a SSL socket to another process would need this internal SSL state to be transferred too. But, Python has no direct access to this state because it only uses the OpenSSL library with the Libraries API and thus can not transfer it.
My app communicates with an external server using AsyncSocket as a Client.
(the working code can be found here)
When the app starts, the user types in the IP address of the server computer.
assuming both iOS and server is sitting on the same subnet
Question: is there a way to "scan" the network for the server thus avoiding the user manual input for server IP ?
I can iterate the IPs one by one in a loop (10.0.1.x 10.0.1.x++)
yet it seems wrong and wasteful.
is there another more elegant way to do so?
I had an iOS project doing server discovery in the current (Wi-Fi) network. The typical solution is to use UDP broadcasting to ask for server info and then listen to a UDP response. As soon as you get the response with the server address you can establish connection using TCP sockets.
CocoaAsyncSocket is good enough for this. I used GCDAsyncUdpSocket and GCDAsyncSocket.
I understand you probably need more info on the topic. I'll try to extend the answer when I have time to.
I discovered today that if I ssh-forward the local port X to ssh server port Y, and no process is listening on port Y, I can still connect to local port X (I don't get the usual "connection refused" error).
I did my test with 2 different SSH clients on a windows host connecting to a linux server.
After a bit of reflexion, I came to the conclusion that from a pure network point of view, this is the behaviour I should expect: the SSH client is actually listening on localhost:X, so the connection is possible.
Nevertheless, this leads to a problematic situation in which I have an apparently connected socket that talks to nobody. Even sending data on the socket is a successful operation.
So my question: does the SSH protocol manage this situation in some ways, i.e. do I have strategies for detecting this situation? And if yes, may I hope support for this feature on some SSH clients and APIs (today I'm using ssh.net, that does not seem to offer this feature).
If not, how would you proceed for detecting the situation? Timeout on answer?
Thanks for your help,
Alberto.
The only logical behavior would be to close client connection if the server can't connect to the remote side, but that would not be much better than just a hanging connection.
Also there can happen situation when the SSH server is waiting for the remote connection for a minute or two before giving up, so the client's connection will be opened for this period of time anyway.
So there's actually no logical alternative rather than a hanging client connection.
Alright, so I figure I will ask the awesome stackoverflow community to see if I can get an answer.
My question is, I want to run a script, php specifically but I could do any type technically whenever a connection comes into haproxy. I can chnage my load balancing software if needed or use a non load balancing software too.
Order of events
Connection attempt via haproxy
haproxy sees that it is a certain port/port range
haproxy triggers script
haproxy forwards connection like it is supposed to.
How could this be possible? Also the script needs to trigger before it forwards the traffic
I figure someone will ask, so I will explain in advance. I have an online game, but I don't want it running all the time. If someone tries to connect it starts the game via an api/script.
Update *
I was thinking about the logic. What you could do is set a service to listen for these ports on the game server and then when it sees a connection run the script that shutsdown the listener and starts the game but you would want to automatically restart the listener if the game shuts down.
I really don't understand your logic...why you are wanted to do so....
Following are URL show how you can configure HAproxy to trigger a xinetd script. I understand this is really something you want , but least it will gives you clues for exact solution.
http://sysbible.org/2008/12/04/having-haproxy-check-mysql-status-through-a-xinetd-script/
I have been looking around for a solution that implements this, but google always gives me tutorials on establishing a live chat over an ssh tunnel--not the other way around.
I suspect this can be implemented just using tunnels (if it is possible at all), but I am not sure how.
I am sorry if this has been asked, but after looking through the related questions, but I have not been able to find one that I can be sure will work for my particular needs (i.e. I cannot create an ssh session directly with gmail.com etc.) If I am wrong, please just post a link to the applicable question.
If you can establish connections between peers via your IRC channel, then there is a solution.
Don't try to fiddle with IRC itself, but build a solution on top of it.
Use ssh yourself on top of IRC.
I mean create a SSH/SSL connection to a dummy socket you can use to intercept the data sent by SSH. Transform this data (if necessary) to make it transportable via IRC. And send it to the remote peer via IRC.
On the remote peer, intercept your data, un-transform it before giving it to your ssh/ssl connection listener. And proceed the same way to send response.
If the connection is successful ssh will tell you and your can start pouring your data through this secure 'channel'.
Your data going via IRC will be safe, because ssh is.