Last active
October 13, 2023 16:18
Star
You must be signed in to star a gist
Weird issue
This file contains 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
// Execute this normally in a browsers debug console. | |
const ws = new WebSocket('ws://127.0.0.1:8080/'); | |
ws.onopen = async () => { | |
// Send different 1mb arrays. | |
for (let i = 0; i < 10; i++) { | |
const data = new Uint8Array(1024 * 1024); | |
for (let j = 0; j < 1024 * 1024; j++) { | |
data[j] = i; | |
} | |
ws.send(data); | |
} | |
}; |
This file contains 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
package main | |
import ( | |
"fmt" | |
"github.com/gorilla/mux" | |
"github.com/gorilla/websocket" | |
"net/http" | |
"time" | |
) | |
func websocketHandler(w http.ResponseWriter, r *http.Request) { | |
upgrader := websocket.Upgrader{} | |
upgrader.CheckOrigin = func(r *http.Request) bool { return true } | |
ws, _ := upgrader.Upgrade(w, r, nil) | |
defer ws.Close() | |
for i := 0; i < 10; i++ { | |
_, fileBytes, _ := ws.ReadMessage() | |
fmt.Println(fileBytes[0:10]) | |
// Represents taking 1 second to process uploaded data. | |
time.Sleep(time.Second * 1) | |
} | |
} | |
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/", websocketHandler).Methods("GET") | |
_ = http.ListenAndServe("127.0.0.1:8080", r) | |
} |
This file contains 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
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket | |
class SimpleEcho(WebSocket): | |
def handleMessage(self): | |
print(self.data[0:10]) | |
def handleConnected(self): | |
print(self.address, 'connected') | |
def handleClose(self): | |
print(self.address, 'closed') | |
server = SimpleWebSocketServer('127.0.0.1', 8080, SimpleEcho) | |
server.serveforever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment