From Ape Wiki

(Redirected from Protocol Basics)
Jump to: navigation, search
This page covers APE protocol 1.0

Contents

APE Protocol Basics

Request to server

Either POST or GET is allowed as the HTTP method. The url querystring (if GET is used) or the request body (if POST is used) must be added after ? with the value of a json-encoded array.

Requests to a server are done on the following URL :

http://[Frequency].[Server URL]/?

GET example :

GET /?[{"cmd":"CONNECT","chl":0,"params":{"transport":0}}] HTTP/1.1
Host: 0.ape.ape-project.org

POST example :

POST /? HTTP/1.1
Host: 0.ape.ape-project.org
 
[{"cmd":"CONNECT","chl":0,"params":{"transport":0}}]

The Host header is used to detect new sub user, this feature allows multiple windows/tabs. See Session for more information.

Raw and Command

The APE Protocol works with a system of Raw and Command. Raws and commands are in JSON format. They are always sent as JSON arrays, each entry of the array is a JSON object representing a raw or a command.

Raw

A raw refers to data sent by the server to the client. A raw is a JSON object with the following mandatory keys:

  • raw: Name of the raw
  • time: Time of the server when the raw as sent
  • data: A JSON object

[
    {
        "raw":"<raw name>",
        "time":"<Send time of the raw>",
        "data":{}
    }
]

Command

A command refers to data sent from the client to the server. A command is a JSON object with the following mandatory keys:

  • cmd: Name of the command
  • chl: Challenge, the challenge is as integer incremented to every request sent to server.

[
    {
        "cmd":"<command name>",
        "chl":<challenge>
    }
]

TODO : Sessid? Carry return forbiden?


Transport

TODO

Server side storage

The protocol allows storage of variables on the server side. The client can store key/value pairs on the server. Values stored are kept until the user disconnects or timeouts. For more information see store raw and retreive command.

Handshake

The client initiates a connection negotiation by sending a CONNECT command.

[
    {"cmd":"CONNECT","chl":0,"params":{"transport":0}}
]

For more information see reference of connect command

The server respond with two raws :

[
    {"raw":"LOGIN","time":"1253633967","data":{"sessid":"4622c258248931a7dfb081542eaf589f"}},
    {"raw":"IDENT","time":"1253633967","data":{"user":{"casttype":"uni","pubid":"5288a462f528d3609777f31872d31c8d"}}}
]

For more information see reference of login raw and ident

TODO : Explain sessid? Fix broken links?

Session

The APE Protocol has a session feature. This feature is used to handle multiple windows/tabs. Each window/tab must use a different url to connect to server. If the server in the http header detects a different host from the same client (client is identified with pubid) it must first send a raw IDENT and CHANNEL (if user are on any channel). Each raw sent by server must be forwarded to other client. This feature is also used to restore the state of an application after a user refreshes the page.

Here is a session example:

Client 0:

POST /? HTTP/1.1
Host: 0.ape.ape-project.org
 
[{"cmd":"CONNECT","chl":0,"params":{"transport":0}}]

Server respond to client 0 :

[{"raw":"LOGIN","time":"1253633967","data":{"sessid":"4622c258248931a7dfb081542eaf589f"}}, {"raw":"IDENT","time":"1253633967","data":{"user":{"casttype":"uni","pubid":"5288a462f528d3609777f31872d31c8d"}}}]

Client 1 : (user opened a new window)

POST /? HTTP/1.1
Host: 1.ape.ape-project.org
 
[{"cmd":"CHECK","chl":1,"sessid":"4622c258248931a7dfb081542eaf589f"}]

Server respond to client 1 :

[{"raw":"LOGIN","time":"1253633967","data":{"sessid":"4622c258248931a7dfb081542eaf589f"}}, {"raw":"IDENT","time":"1253633967","data":{"user":{"casttype":"uni","pubid":"5288a462f528d3609777f31872d31c8d"}}}]

Client 1 : (user join a channel)

POST /? HTTP/1.1
Host: 1.ape.ape-project.org
 
[{"cmd":"JOIN","sessid":"4622c258248931a7dfb081542eaf589f","chl":1,"params":{"channels":["testChannel"]}}]

Server respond to client 0 and 1 :

{"raw":"CHANNEL","time":"1253640697","datas":{"pipe":{"properties":{"name":"testChannel"},"casttype":"multi","pubid":"2f50f03539dfe782e233d0a76205b3f3"},"users":[{"level":"1","casttype":"uni","pubid":"4622c258248931a7dfb081542eaf589f"}]}}