Hi there,
First of all, you can have a look agh this to see how I did it on iOS :
https://github.com/lcharette/APE_iOS_Client
The goal here is first to communicate with the APE Server. I never experienced
web socket because iOS doesn’t natively support it, but I guess it should work
the same as plain socket (which I used in the iOS client). The dialogue between
your app (java) and APE is basically a series of HTTP request over a TCP
connexion. You use a socket (or web socket) to write and read HTTP request.
The URL you use, as Pablo pointed out, will depend on the method you use. But
for plain socket, I suggest you simply use ip:port or APEdomain:port to connect
to the socket and then pass the rest in the request. The « /1/» transport
should be better for socket connection. Once the socket is open, You can write
to it like this and the server will respond.
Notes:
The first request you write needs to specify the host (GET
/1/?{YOUR_JSON_OBJECT} HTTP/1.1\nHost: 0\n\n)
Subsequent request can omit the host (GET /1/?{YOUR_JSON_OBJECT}\n\n)
Notice the two line break at the end. This tells APE to precess the command.
For example:
GET /1/?[{"cmd":"CONNECT","chl":0,"params":{"name":"iOS980"}}] HTTP/1.1
Host: 0
The server will answer with something like this :
HTTP / 1.1 200 OK
Pragma: no - cache
Cache - Control: no - cache,
must - revalidate
Expires: Thu,
27 Dec 1986 07: 30: 00 GMT
Content - Type: application / x - ape - event - stream
[{
"time": "1398873326",
"raw": "LOGIN",
"data": {
"sessid": "7f944f2c86eb0a687870ee0fdde6ebfb"
}
}, {
"time": "1398873326",
"raw": "IDENT",
"data": {
"user": {
"casttype": "uni",
"pubid": "0f6b4fe3c2423110ff744d970e340966",
"properties": {
"name": "iOS980"
}
}
}
}]
[Ref: https://gist.github.com/lcharette/1e87882f58011f0340e5]
All you need to do now is to parse the json response from the server. You can
try this using a socket test app like this one :
http://sockettest.sourceforge.net/
Please note, you’ll need the latest dev version of APE to make it work
properly. Otherwise, long command will fail. The current GitHub version is
stable and should be bundle as 1.1.3 final really soon :
https://github.com/APE-Project/APE_Server
This server side example can also be useful to understand how communicating
with APE using a socket works :
https://github.com/APE-Project/APE_Server/blob/master/scripts/examples/ircserver.js
Hope this help a little ;)
- Louis
Le 2014-04-30 à 08:57, Pablo Tejada <[email protected]> a écrit :
> I think the key here is to specified the correct transport in the URL. I dont
> know java but i would suggest using a websocket client if available and the
> APE websocket transport.
>
> From the top of my the URL for a websocket connection would look like this:
>
> wss://yourAPE.com/6/?
>
> For raw HTTP long polling:
>
> http://yourAPE.com/0/?
>
> The reason why the previous user did not received a CLOSE raw could because
> the connection was established using the long polling and for this specific
> transport the client might need to manually close the connection. OR it could
> be that the check command was sent to a different frequency/subdomain. For
> example before sending another CHECK command close any existing pending
> request, although i think APE might close any pending requests if a second
> request is send to the same frequency.
>
> As previously suggested it would be easier to implement the websocket
> transport since you dont have deal with closing and opening connection.
>
> On Apr 30, 2014 5:07 AM, "Marcin Michałek" <[email protected]>
> wrote:
> I know the topic is outdated, but any luck in implementing APE in Java?
> I am triyng to do the same for Android, but I am stuck.
>
> On Tuesday, June 29, 2010 2:46:44 PM UTC+2, stéphane Herraiz wrote:
> Hi,
>
> I'm trying to make a APE client in Java (Android).
>
> I'm connecting to the APE server using a CONNECT/JOIN command.
> Then I send a CHECK cmd :
> ["cmd":"CHECK","chl":3,"sessid":"34d2dd64e1bb3d1c17add2b216a87551"}]
> I have put a socket timeout to 30s
> When a message arrive I can read it but I never receive the CLOSE
> raw : [{"time":"1277815119","raw":"CLOSE","data":{"value":"null"}}]
> when no message is coming. I have a timeout.
> What is wrong in my implementation?
>
> Thanks a lot in advance
>
> BR
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "APE Project" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/ape-project?hl=en
> ---
> APE Project (Ajax Push Engine)
> Official website : http://www.ape-project.org/
> Git Hub : http://github.com/APE-Project/
>
> ---
> You received this message because you are subscribed to the Google Groups
> "APE Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "APE Project" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/ape-project?hl=en
> ---
> APE Project (Ajax Push Engine)
> Official website : http://www.ape-project.org/
> Git Hub : http://github.com/APE-Project/
>
> ---
> You received this message because you are subscribed to the Google Groups
> "APE Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/
---
You received this message because you are subscribed to the Google Groups "APE
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.