[Debugging] Please make debug port (8081) configurable
Port 8081 is currently used by react-native as the debugging port in the following files:
Libraries/RCTTest/RCTTestRunner.m
Libraries/WebSocket/RCTWebSocketExecutor.m
React/Base/RCTRedBox.m
React/React.xcodeproj/project.pbxproj
Unfortunately there are other services that might use 8081, i.e. McAfee:
| Port | Default | Description | Traffic direction |
|---|---|---|---|
| Agent wake-up communication port SuperAgent repository port | 8081 | TCP port that agents use to receive agent wake-up requests from the ePO server or Agent Handler... | Inbound connection from the ePO server/Agent Handler to the McAfee Agent... |
See https://kc.mcafee.com/corporate/index?page=content&id=KB66797
Another reason for having a configurable react-native debug port is that I often work on two react-native projects in parallel, i.e. my own project plus UIExplorer. But both react-native apps collide, because both want to use port 8081.
Please make react-native's debug port configurable in order to avoid conflicts with other services.
@bparadie - do you have time to submit a PR for this?
@brentvatne Right now I don't have a lot of time. But I can prepare a PR. First I wanted to know whether there is interest in this change. It looks like there is, correct?
I think so. A good approach to make things configurable without stepping on too many toes could be to define a macro like RCT_WEBSOCKET_PORT so that it's as configurable as RCT_DEV, etc.
Should this also include configuring the IP address (replacing localhost)?
@jsierles Yeah, I think IP address should be configurable as well.
@bparadie - agreed!
@jsierles @ide @brentvatne Before I go ahead and implement something that nobody wants, I'd like to ask you guys whether you find this direction agreeable:
How about reading the information for port (8081) and origin ('http://localhost') from a dictionary in info.plist?
Roughly, I was thinking of adding a new dictionary to info.plist called RCTWebSocketExecutor with port and origin items. For example this would be UIExplorer's info.plist:

Then in RCTWebSocketExecutor:init I would check whether there is a RCTWebSocketExecutor dictionary and use those values for initWithURL. If there is no RCTWebSocketExecutor dictionary I'd use 8081 and 'http://localhost'.
Also, let me know if you think there are better names for RCTWebSocketExecutor, port, and origin.
Thanks!
Oh, I almost forgot: Then packager probably needs to be adjusted. I could perhaps simply extract port and originfrom the info.plist.
This seems like a good approach. Easy to point people here, and plist files are easy to edit programatically. What about the IPs/ports for non-websocket?
@jsierles Apologies if this is a stupid question: What are 'non-websocket' IPs/ports?
@jsierles @ide @brentvatne Just wanted to dog-pile one other idea to this PR. We could change the name from RCTWebSocketExecutor to, say, AppImage and add a property bundle / name in addition to origin and port. If bundle is specified the default AppDelegate code would use the bundle instead of the web socket etc.
What do you guys think?
@bparadie: bundles (I assume you mean JS bundles and not iOS asset bundles) and the web socket executor are independent. You could run a bundle across the web socket executor if you wanted. Best to keep the two concepts separate.
This is the code snippet I am planning to use in AppDelegate.m and RCTWebSocketExecutor.m:
NSMutableString* url;
NSDictionary *dict = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTWebSocketExecutor"];
if( dict )
{
NSString* origin = [dict objectForKey:@"origin"];
NSString* port = [NSString stringWithFormat:@"%@", [dict objectForKey:@"port"]];
url = [NSMutableString stringWithString:origin];
[url appendString:@":"];
[url appendString:port];
}
else
{
url = [NSMutableString stringWithString:@"http://localhost:8081"];
}
I have three questions:
- Should I put this in a utility function and call it from
AppDelegate.mandRCTWebSocketExecutor.m? If so what's a good place to add that utility function? - Should every example use this snippet, or should I just show how it works in one of the examples?
- Would it be ok to assume that there is always a valid
Info.plistentry forRCTWebSocketExecutor? If so then the code could be compressed to:
NSDictionary *dict = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTWebSocketExecutor"];
NSString* origin = [dict objectForKey:@"origin"];
NSString* port = [NSString stringWithFormat:@"%@", [dict objectForKey:@"port"]];
NSMutableString* url = [[[NSMutableString stringWithString:origin] appendString:@":"] appendString:port];
@jsierles @ide @brentvatne I have something that works. This is a screenshot after changing the port number to 8086 in Info.plist and rebuilding UIExplorer:

But it's not pretty:
- I had to add a new target called
ReactWithoutPackagertoReact.xcodeprojthat is a copy of theReacttarget without running thelaunchPackager.commandscript. UIExplorernow links againstlibReactWithoutPackager.a, which attracts theReactWithoutPackagertarget w/olaunchPackager.command.- I had to add support for
--originparameter topackager.sh - I had to add a run script to
UIExplorerthat launcheslaunchPackager.commandwith--originand--portparameters. - I can't use
open launchPackager.command, because I am now passing--originand--portas parameters andopenw/t--argsdoes not seem to work withTerminal
I've create this fake PR against my private repo: https://github.com/bparadie/react-native/pull/2/files
As you can see I decided to not switch everything over to Info.plist. People can still use the old way with hard-coded 'http://localhost:8081'.
Are my changes acceptable?
If so I'll submit an official PR against facebook/master
@brentvatne np, done: https://github.com/facebook/react-native/pull/1546 !
Looks good @bparadie!
+1
Here's my hack for how to get Android running https://github.com/mjohnston/react-native-webpack-server/issues/65#issuecomment-151222398
I've posted this on product pains so it would be great if you could upvote it there and show the react-native team that this is an important feature https://productpains.com/post/react-native/allow-packager-port-to-be-configurable-change-from-8081/
If someone could send a PR it would be great.
I haven't deleted the branch yet: https://github.com/bparadie/react-native/tree/webSocketConfig
But I am afraid I am not going to re-submit this PR. I've spent too much time keeping that branch up to date with master and formatting it only to learn that nobody had interested in reviewing and approving it.