Skip to content

Instantly share code, notes, and snippets.

@ananace
Last active December 25, 2015 18:58
Show Gist options
  • Save ananace/7023952 to your computer and use it in GitHub Desktop.
Save ananace/7023952 to your computer and use it in GitHub Desktop.
XM
Current Server:
IP: 88.206.179.92
Port: 4567
Message:
Header - 5 bytes, network order:
Flags - 1 byte:
SYN - 1
ACK - 2
FIN - 4
ID - 2 bytes, server increments with every packet
Size - 2 byte (including the header)
Sanity - 2 bytes, always 'XM'
Command - 4 bytes:
'noop' - Non-operation, does nothing at all
'stor' - Store this connection in the database
'ping' - Keepalive ping
'pong' - Keepalive ping response
'conn' - Connect to another client using their id
Parameters (JSON):
stor:
ip (string) - The IP of your sockets private endpoint (0.0.0.0 is okay)
port (number) - The Port of your sockets private endpoint
conn:
id (string) - The ID to connect to
Responses (JSON):
stor:
ok (bool), if true then:
id (string) - The ID
[error] (string) - Error message if failed
pong:
ok (bool)
[error] (string)
conn:
ok (bool), if true then:
public: - The public endpoint of the other client
ip (string)
port (number)
private: - The private endpoint of the other client
ip (string) - Might be "0.0.0.0", in that case use the public IP
port (number)
[error] (string)
For each package send a SYN, wait for a SYN|ACK and then respond with an ACK. Message data is only provided in the original SYN message, the SYN|ACK and ACK only uses the packet ID.
If a SYN|ACK is not given, resend the packet five times with an interval of five seconds, if you still don't get a response assume the connection died.
Sample packages where '->' denotes a sent package, and '<-' denotes a received package:
-> \x01\x00\x01\x00\x2aXMstor{"ip":"127.0.0.1","port":12345}
<- \x03\x00\x01\x00\x24XMstor{"ok":true,"id":"screen"}
-> \x02\x00\x01\x00\x05XM
-> \x01\x00\x02\x00\x0bXMping
<- \x03\x00\x02\x00\x16XMpong{"ok":true}
-> \x02\x00\x02\x00\x05XM
-> \x01\x00\x03\x00\x00XMconn{"id":"bathtub"}
<- \x03\x00\x03\x00\x67XMconn{"ok":true,"private":{"ip":"0.0.0.0","port":12345},"public":{"ip":"127.0.0.1","port":54321}}
-> \x02\x00\x03\x00\x05XM
-> \x04\x00\x04\x00\x05XM
<- \x06\x00\x04\x00\x05XM
(Server has closed connection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment