You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually, I am getting a timeout when trying to connect to the socket. Could you please help me ?
2025/12/15 15:02:21 read tcp 192.168.****.:44530->136.243.173.177:443: i/o timeout
func startAISStream(ctx context.Context, pool *pgxpool.Pool, apiKey string) {
url := "wss://stream.aisstream.io/v0/stream"
fmt.Println("web socket is about to start")
ws, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
log.Fatalln(err)
}
defer ws.Close()
subMsg := aisstream.SubscriptionMessage{
APIKey: apiKey,
BoundingBoxes: [][][]float64{{{-90.0, -180.0}, {90.0, 180.0}}}, // bounding box for the entire world
}
subMsgBytes, _ := json.Marshal(subMsg)
if err := ws.WriteMessage(websocket.TextMessage, subMsgBytes); err != nil {
log.Fatalln(err)
}
for {
_, p, err := ws.ReadMessage()
if err != nil {
log.Fatalln(err)
}
var packet aisstream.AisStreamMessage
err = json.Unmarshal(p, &packet)
if err != nil {
log.Fatalln(err)
}
var shipName string
// field may or may not be populated
if packetShipName, ok := packet.MetaData["ShipName"]; ok {
shipName = packetShipName.(string)
}
switch packet.MessageType {
case aisstream.POSITION_REPORT:
var positionReport aisstream.PositionReport
positionReport = *packet.Message.PositionReport
fmt.Printf("MMSI: %d Ship Name: %s Latitude: %f Longitude: %f\n",
positionReport.UserID, shipName, positionReport.Latitude, positionReport.Longitude)
}
}
Activity
vs41 commentedon Dec 15, 2025
Actually, I am getting a timeout when trying to connect to the socket. Could you please help me ?
2025/12/15 15:02:21 read tcp 192.168.****.:44530->136.243.173.177:443: i/o timeout
func startAISStream(ctx context.Context, pool *pgxpool.Pool, apiKey string) {
}