기본 콘텐츠로 건너뛰기

7월, 2023의 게시물 표시

[golang/websocket] websocket sample

0.소스 올린 이유. 샘플이라고 올라와 있지만, 실제로는  접속 실패 오류가 떠서 한참 구글링 했습니다. server1.go 실행하고 client1.go 로 동작 확인하고, 웹 동작은 크롬 브라우저에서 websocket_client1.html 동작 확인 했습니다. 아래는 WebSocket 동작 샘플 소스 이며, 아래 링크에 있는 샘플들을 참고 했습니다. https://github.com/gorilla/websocket https://github.com/gorilla/websocket/tree/main/examples/chat https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api https://www.golinuxcloud.com/golang-websocket/ https://www.tutorialspoint.com/webrtc/webrtc_rtcpeerconnection_apis.htm server1.go package main import ( "fmt" "log" "net/http" "github.com/gorilla/websocket" ) // var upgrader = websocket.Upgrader{} var upgrader = websocket.Upgrader{ ReadBufferSize:  1024, WriteBufferSize: 1024,          // 아래 CheckOrigin 항목이 없으면, 크롬에서 클라이언트 올렸을때 접속 안됨. CheckOrigin: func(r *http.Request) bool {         return true     }, } func main() { http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) { conn,