MCPcopy Create free account
hub / github.com/djherbis/socket

github.com/djherbis/socket @v0.9.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.1 ↗ · + Follow
105 symbols 215 edges 14 files 28 documented · 27% updated 5y agov0.9.1 · 2021-04-25★ 43

Browse by type

Functions 83 Types & classes 22
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

socket

GoDoc Software License

Simple Socket.io alternative with #golang server

Usage

Server:

package main

import (
  "fmt"
  "net/http"

  "github.com/djherbis/socket"
)

type MyObject struct{
  Text string `json:"text"`
}

func main() {
  server := socket.NewServer()

  server.On(socket.Connection, func(so socket.Socket) {
    so.Emit("hello", "world")

    so.On("hey", func(msg string) {
      fmt.Println(msg)
    })

    so.On("new obj", func(myobj MyObject){
      fmt.Println(myobj)
    })

    so.Emit("server obj", MyObject{Text: "obj from server to client"})
  })

  router := http.NewServeMux()
  router.Handle("/socket", server)
  router.Handle("/", http.FileServer(http.Dir("."))) // serve up socket.js
  http.ListenAndServe("localhost:8080", router)
}

Client:

<script src="https://github.com/djherbis/socket/raw/v0.9.1/socket.js"></script>
<script>
  var socket = io("localhost:8080/");

  socket.emit("hey", "hey there!");

  socket.on("hello", function(msg){
    console.log(msg);
  });

  socket.emit("new obj", {text: "objects are automatically marshalled/unmarshalled"});

  socket.on("server obj", function(myobj){
    console.log(myobj);
  });
</script>

Installation

# Server Side
go get github.com/djherbis/socket

# Client Side
<script src="https://github.com/djherbis/socket/raw/v0.9.1/socket.js"></script>

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 67
Function 16
Struct 12
Interface 10

Languages

Go100%

Modules by API surface

transport.go24 symbols
socket.go16 symbols
room.go13 symbols
client.go13 symbols
namespace.go11 symbols
handler.go9 symbols
server.go5 symbols
rooms.go5 symbols
caller.go5 symbols
example/main.go2 symbols
example/hook/server.go1 symbols
example/hook/client.go1 symbols

For agents

$ claude mcp add socket \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page