eklektek
eklektek

Reputation: 1173

Simple OS X TCP forwarding server/service

As part of a TDD (test driven development) project I want a simple OSX service/server that simply forwards data between two clients. The purpose is to enable communication between one piece of code running in iOS (being tested) and another running in OS X.

I think I need both parties to connect to the server for the duration of the test, which points at TCP

There are lots of examples for creating simple clients using NSStream, but have failed to find what creates the Server side.

Upvotes: 3

Views: 3083

Answers (2)

Ruby
Ruby

Reputation: 103

Port Forwarding In Windows for iOS .

 1. Install Python 2.7 on windows system 
 2. Connect your iPhone to windows system 
 3. Download USB MXD1.0 and put it in C Drive
 4. Run Command Prompt : OpenC:\usbmuxd-1.0.8\python-client in cmd 
 5. Run **\Python27\python.exe tcprelay.py -t local port:remote Port**
     Eg :**\Python27\python.exe tcprelay.py -t 9892:9892**

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122421

I would have thought it would be normal for this forwarding software to be a client of the final server, rather than both the other pieces of code being a client to it (as it's both counter-intuitive and somewhat difficult to acheive):

iOS App -> Forwarding Server -> OSX Server

You can achieve this using netcat (which is installed by default on OSX), simply with:

$ nc -l -p local-port -c "nc osx-host osx-port"

(see below)

and the iOS app simply needs to connect to local-port on whatever machine this forwarding server is running on.

EDIT When I actually tested my answer I found that the netcat supplied with OSX cannot support port forwarding, and the answer I supplied only works with the Linux version (I believe there is a BSD-rewrite which OSX uses).

Anyway, this can be achieved if you are happy to install macports and use socat. Here's a working example that redirects port 8888 to www.google.com:80:

$ sudo port install socat
$ socat TCP-LISTEN:8888,fork TCP:www.google.com:80

If you then connect to http://localhost:8888 within your browser, this will hit Google.

Upvotes: 6

Related Questions