Skip to content

Instantly share code, notes, and snippets.

@nornagon
Created December 4, 2018 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nornagon/580525977e9daf7c4ee0db6971fe3727 to your computer and use it in GitHub Desktop.
Save nornagon/580525977e9daf7c4ee0db6971fe3727 to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!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>
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()
}
})
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