Created
December 4, 2018 00:59
-
-
Save nornagon/580525977e9daf7c4ee0db6971fe3727 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<!-- All of the Node.js APIs are available in this renderer process. --> | |
We are using Node.js <script>document.write(process.versions.node)</script>, | |
Chromium <script>document.write(process.versions.chrome)</script>, | |
and Electron <script>document.write(process.versions.electron)</script>. | |
<script> | |
// You can also require other files to run in this process | |
require('./renderer.js') | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require('ws') | |
const {app, BrowserWindow} = require('electron') | |
// Set up a local SOCKS proxy with: | |
// $ ssh localhost -D4096 | |
app.commandLine.appendSwitch('proxy-server', 'socks5://localhost:4096') | |
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1') | |
// Uncomment the following line to lift the connection limit | |
// app.commandLine.appendSwitch('ignore-connections-limit', 'blah.com') | |
const wss = new WebSocket.Server({port: 9012}) | |
let mainWindow | |
function createWindow () { | |
mainWindow = new BrowserWindow({width: 800, height: 600}) | |
mainWindow.loadFile('index.html') | |
mainWindow.on('closed', function () { | |
mainWindow = null | |
}) | |
} | |
app.on('ready', createWindow) | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') { | |
app.quit() | |
} | |
}) | |
app.on('activate', function () { | |
if (mainWindow === null) { | |
createWindow() | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nOpen = 0 | |
let nError = 0 | |
const next = () => { | |
if (nOpen >= 300) | |
return | |
const ws = new WebSocket('ws://blah.com:9012') | |
ws.onopen = () => { | |
nOpen++ | |
ws.send(nOpen.toString()) | |
document.body.textContent = `${nOpen}/${nError}` | |
next() | |
} | |
ws.onerror = (e) => { | |
console.log(e) | |
nError++ | |
document.body.textContent = `${nOpen}/${nError}` | |
next() | |
} | |
} | |
next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment