react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Debugging] Please make debug port (8081) configurable

Open bparadie opened this issue 11 years ago • 38 comments

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 avatar May 27 '15 20:05 bparadie

@bparadie - do you have time to submit a PR for this?

brentvatne avatar May 29 '15 17:05 brentvatne

@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?

bparadie avatar May 29 '15 17:05 bparadie

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.

ide avatar May 29 '15 18:05 ide

Should this also include configuring the IP address (replacing localhost)?

jsierles avatar May 29 '15 19:05 jsierles

@jsierles Yeah, I think IP address should be configurable as well.

bparadie avatar May 29 '15 21:05 bparadie

@bparadie - agreed!

brentvatne avatar May 30 '15 21:05 brentvatne

@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:

screen shot 2015-05-31 at 3 07 57 pm

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.

bparadie avatar May 31 '15 22:05 bparadie

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 avatar Jun 01 '15 08:06 jsierles

@jsierles Apologies if this is a stupid question: What are 'non-websocket' IPs/ports?

bparadie avatar Jun 01 '15 16:06 bparadie

@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 avatar Jun 01 '15 16:06 bparadie

@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.

ide avatar Jun 01 '15 23:06 ide

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.m and RCTWebSocketExecutor.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.plist entry for RCTWebSocketExecutor? 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];

bparadie avatar Jun 06 '15 22:06 bparadie

@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:

screen shot 2015-06-06 at 4 46 09 pm

But it's not pretty:

  • I had to add a new target called ReactWithoutPackager to React.xcodeproj that is a copy of the React target without running the launchPackager.command script.
  • UIExplorer now links against libReactWithoutPackager.a, which attracts the ReactWithoutPackager target w/o launchPackager.command.
  • I had to add support for --origin parameter to packager.sh
  • I had to add a run script to UIExplorer that launches launchPackager.command with --origin and --port parameters.
  • I can't use open launchPackager.command, because I am now passing --origin and --port as parameters and open w/t --args does not seem to work with Terminal

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

bparadie avatar Jun 06 '15 23:06 bparadie

@brentvatne np, done: https://github.com/facebook/react-native/pull/1546 !

bparadie avatar Jun 07 '15 20:06 bparadie

Looks good @bparadie!

jsierles avatar Jun 12 '15 11:06 jsierles

+1

schickling avatar Jun 19 '15 12:06 schickling

Here's my hack for how to get Android running https://github.com/mjohnston/react-native-webpack-server/issues/65#issuecomment-151222398

niftylettuce avatar Oct 26 '15 17:10 niftylettuce

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/

qimingweng avatar Dec 24 '15 17:12 qimingweng

If someone could send a PR it would be great.

satya164 avatar Dec 24 '15 18:12 satya164

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.

PublicParadise avatar Dec 26 '15 17:12 PublicParadise