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
This is a javascript client project for [jetserver](https://github.com/menacher/java-game-server/tree/master/jetserver) library. An example html which can connecct to a locally running Jetserver is located at src/test/jetclient.html .
2
+
3
+
About the Client
4
+
================
5
+
Click on `start war` button after loading jetclient.html in a websocket enabled browser to start the game. Assumption is that JetServer is running and jetclient.html is using accurate hostname and port number.
6
+
7
+
Usage as your own game client
8
+
=============================
9
+
The general usage steps could be as outlined below.
10
+
1. Create a config object containing the username, password and connectionkey to connect to game room. If you are using a different protocol, then add the appropriate codec chains also to the config object. By default JSon encoding/decoding is used.
11
+
2. Create a session using the session factory by passing in a url for the remote jetserver, config object and a callback function which will receive the session object after successful login to remote jeteserver.
12
+
3. Create as many sessions as required using this factory. Generally only one is required for a client. In the example 50 sessions are created.
13
+
4. Add necessary handlers to the session using `addHandler` function. The default events generated are provided the jet.Events class. At the very least you would want to add a handler for the jet.Events.SESSION_MESSAGE event to receive incoming events from jetserver.
14
+
5. Data can be send to remote server using `session.send` function.
// If using a differnt protocol, then use this codec chain, to decode and encode incoming and outgoing requests. Something like a Chain of Responsibility pattern.
54
+
jet.CodecChain=function(){
55
+
varme=this;
56
+
me.chain=[];
57
+
for(vari=0;i<arguments.length;i++){
58
+
me.chain.push(arguments[i]);
59
+
}
60
+
61
+
me.add=function(func){
62
+
me.chain.push(func);
63
+
};
64
+
65
+
me.remove=function(func){
66
+
varindex=me.chain.indexOf(func);
67
+
while(index!=-1){
68
+
me.chain.splice(index,1);
69
+
index=me.chain.indexOf(func);
70
+
}
71
+
};
72
+
73
+
me.tranform=functiontransform(message){
74
+
for(vari=0;i<me.chain.length();i++){
75
+
message=me.chain[i].transform(message);
76
+
}
77
+
returnmessage;
78
+
};
79
+
};
80
+
81
+
// Default codes which use JSON to decode and encode messages.
0 commit comments