|
34 | 34 | import java.awt.Point; |
35 | 35 | import java.io.*; |
36 | 36 | import java.net.ConnectException; |
| 37 | +import java.net.InetAddress; |
| 38 | +import java.net.UnknownHostException; |
37 | 39 | import java.util.*; |
38 | 40 |
|
39 | 41 | import com.sun.jdi.*; |
@@ -82,6 +84,8 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException { |
82 | 84 | // this.sketch = sketch; |
83 | 85 | this.build = build; |
84 | 86 |
|
| 87 | + checkLocalHost(); |
| 88 | + |
85 | 89 | if (listener instanceof Editor) { |
86 | 90 | this.editor = (Editor) listener; |
87 | 91 | sketchErr = editor.getConsole().getErr(); |
@@ -116,6 +120,29 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException { |
116 | 120 | } |
117 | 121 |
|
118 | 122 |
|
| 123 | + /** |
| 124 | + * Has the user screwed up their hosts file? |
| 125 | + * https://github.com/processing/processing/issues/4738 |
| 126 | + */ |
| 127 | + private void checkLocalHost() throws SketchException { |
| 128 | + try { |
| 129 | + InetAddress address = InetAddress.getByName("localhost"); |
| 130 | + if (!address.getHostAddress().equals("127.0.0.1")) { |
| 131 | + System.err.println("Your computer is not properly mapping 'localhost' to '127.0.0.1',"); |
| 132 | + System.err.println("which prevents sketches from working properly because 'localhost'"); |
| 133 | + System.err.println("is needed to connect the PDE to your sketch while it's running."); |
| 134 | + System.err.println("If you don't recall making this change, or know how to fix it:"); |
| 135 | + System.err.println("https://www.google.com/search?q=add+localhost+to+hosts+file+" + Platform.getName()); |
| 136 | + throw new SketchException("Cannot run due to changes in your 'hosts' file. " + |
| 137 | + "See the console for details.", false); |
| 138 | + } |
| 139 | + |
| 140 | + } catch (UnknownHostException e) { |
| 141 | + e.printStackTrace(); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + |
119 | 146 | public VirtualMachine launch(String[] args) { |
120 | 147 | if (launchVirtualMachine(false, args)) { |
121 | 148 | generateTrace(); |
|
0 commit comments