Skip to content

Networking and more

Networking: networking and the New Namespaces

Section titled “Networking: networking and the New Namespaces”

Two families of networking APIs coexist. The networking namespace is the original P2P packet API (sendP2PPacket, readP2PPacket, acceptP2PSession), and it is unchanged. The new networkingSockets, networkingMessages and networkingUtils namespaces wrap Steam’s Networking Sockets, Networking Messages and Networking Utils interfaces.

  • networking sends unreliable or reliable packets to a SteamID and reads them back in arrival order. There is no connection object, so you cannot close one peer or tell when it dropped.
  • networkingSockets creates listen sockets and connections (by IP address or by SteamID), sends and receives messages with send flags, and groups connections into poll groups. Connections are objects with close, and state queries show whether each one is open.
  • networkingMessages is connectionless, like UDP: send to a SteamID on a channel, receive by channel, and handle session requests and failures. Steam creates the underlying session implicitly.
  • networkingUtils starts relay network access and reports its availability.
const steamworks = require('steamworks.js')
const client = steamworks.init(appId)
// Relay access and authentication: start them early if you expect relayed or authenticated connections
client.networkingUtils.initRelayNetworkAccess()
console.log(client.networkingUtils.getRelayNetworkStatus()) // NetworkingAvailability value
client.networkingSockets.initAuthentication()
// Host: poll the listen socket without waiting, accept connecting peers and take the connection when it is connected
const listen = client.networkingSockets.createListenSocketIp('0.0.0.0:27015')
const event = listen.tryReceiveEvent() // null when nothing is pending
if (event && event.kind === 0 /* Connecting */) {
event.accept()
}
if (event && event.kind === 1 /* Connected */) {
const connection = event.takeConnection()
connection.send(Buffer.from('hello'), 8) // 8 = reliable
console.log(connection.receive(16))
}
// Client: connect by IP address, then close with a reason
const connection = client.networkingSockets.connectByIpAddress('203.0.113.5:27015')
connection.setUserData(1n)
connection.close(1000, 'done', true)
// Messages: accept requests from Steam users and read channel 3
client.networkingMessages.onSessionRequest((request) => request.accept())
client.networkingMessages.sendMessageToUser(friendSteamId, 8, Buffer.from('hi'), 3)
console.log(client.networkingMessages.receiveMessagesOnChannel(3, 10))
  • Send flags are a bitmask of Steam’s k_nSteamNetworkingSend_* values: 0 unreliable, 8 reliable, 1 no Nagle delay. Invalid addresses and closed handles fail with a readable error.
  • Listen socket events and session requests are only produced while runCallbacks() runs. init() already calls it about 30 times a second.
  • A connection or request you never close or answer is closed or rejected when its JavaScript object is garbage collected. Close connections explicitly.
  • Connections and messages need a Steam network path, so they cannot be exercised offline. The offline smoke test only checks that these functions are exported.

Server Browser, Timeline, Screenshots and Remote Play

Section titled “Server Browser, Timeline, Screenshots and Remote Play”

matchmakingServers lists game servers and queries single servers. timeline marks game state and events for Steam’s timeline. screenshots hooks the screenshot hotkey and adds images to the Steam library. remotePlay lists Remote Play Together sessions and sends invites.

const steamworks = require('steamworks.js')
const client = steamworks.init(appId)
// Server list: request, read, then release it
const list = client.matchmakingServers.lanServerList(appId)
try {
for (let i = 0; i < list.getServerCount(); i++) {
const server = list.getServerDetails(i) // ip, port, name, map, players, maxPlayers, ping
console.log(server.name, server.players, server.maxPlayers, server.ping)
}
} finally {
list.release()
}
// Single server: these are Promises and reject when the server does not answer
const ping = await client.matchmakingServers.pingServer('192.168.1.10', 27015)
const players = await client.matchmakingServers.playerDetails('192.168.1.10', 27015)
const rules = await client.matchmakingServers.serverRules('192.168.1.10', 27015)
// Timeline: 0 = Playing (the game mode values are Playing, Staging, Menus, LoadingScreen)
client.timeline.setGameMode(0)
client.timeline.addEvent('icon', 'Boss defeated', '', 0, -5, 5, 1) // clip priority 1 = Standard
// Screenshots: with the hook on, the hotkey raises ScreenshotRequested instead of Steam taking the picture
client.screenshots.hookScreenshots(true)
client.screenshots.triggerScreenshot()
// Remote Play Together
for (const session of client.remotePlay.sessions()) {
console.log(session.sessionId, session.steamId64, client.remotePlay.sessionDetails(session.sessionId))
}
client.remotePlay.invite(friendSteamId)
  • Steam fills a server list over time, through callbacks that init() pumps automatically. Read the count after a short wait, not right after the request. The single-server functions are Promises that resolve the same way.
  • Release every server list request when you finish with it. Methods called after release() throw a readable error.
  • Invalid IPv4 addresses, negative durations and strings with NUL characters are rejected with a readable error before any Steam call.
  • timeline calls are silent when the Steam timeline interface is unavailable.

These functions extend existing namespaces. Nothing that existed before has changed.

const client = steamworks.init(appId)
// apps: the launch command line, and a query parameter from a Steam link such as steam://run/480//mode=demo
client.apps.launchCommandLine()
client.apps.launchQueryParam('mode') // '' when the parameter is absent
// utils: overlay and UI state
client.utils.isOverlayEnabled()
client.utils.isSteamInBigPictureMode()
client.utils.getUiLanguage() // for example 'english'
// input: digital and analog action data, and the origins bound to an action
const pressed = client.input.getDigitalActionData(controllerHandle, actionHandle).state
const stick = client.input.getAnalogActionData(controllerHandle, analogHandle) // { x, y, active }
const origins = client.input.getDigitalActionOrigins(controllerHandle, actionSetHandle, actionHandle)
const label = client.input.getStringForActionOrigin(origins[0] ?? 0)
// networking: P2P packets on a channel, and closing a session
client.networking.sendP2PPacketOnChannel(friendSteamId, SendType.Reliable, Buffer.from('hi'), 2)
client.networking.isP2PPacketAvailableOnChannel(2)
client.networking.closeP2PSession(friendSteamId)
// cloud: share a file (a Promise), stop syncing it, and choose the platforms it syncs to
const shareHandle = await client.cloud.shareFile('save.json')
client.cloud.forgetFile('save.json')
client.cloud.setSyncPlatforms('save.json', 0 /* SyncPlatform.None */)
  • getStringForActionOrigin and getGlyphForActionOrigin return an empty string for an origin number that Steam does not define.
  • getSyncPlatforms rejects when a file syncs to a combination of platforms, because a single SyncPlatform value cannot describe it.
  • shareFile resolves once Steam answers, which happens through runCallbacks(). init() runs it for you.

Turn ideas into shipped software.

HagiCode is an agentic coding workspace. OpenSpec workflows plan the change, multi-agent execution carries it out, and Hero Scenario makes the long run visible, so ideas become shipped software.

Smart
OpenSpec workflows turn intent into a path from proposal to shipped change.
Efficient
Multi-agent execution runs research, build, and review in parallel.
Fun
Rich UI interactions make planning, agent work, and projects easier to follow.