##iGap Client Connection for Android
This repo contains the official source code of iGapSocket Connection On Android system.
##Language
These codes are written in Java language and are used for Android systems.
###The way of connection to server
Because of the possibility of receiving different responses from the server with/without request, in this report, it is used protobuffer for connecting to server.
RequestQueue class is used for sending request to the server. All requests are sent using [sendRequest] method.
sendRequest method is a variadic function that accepts at least unlimited number of input as RequestWraper.
Sending request
1- Create a builder of Intended protobuffer
2- Fill the methods with setters that require decimalisation for sending.
3- Create a new RequestWrapper and then set the number that is corresponded with this proto in the LookupTable as actionId. For example, ConnectionSymmetricKey is corresponded with actionId2. So send it using sendRequest method after filling RequestWrapper by proto and Id.
####Example for sending Request
ProtoConnectionSecuring.ConnectionSymmetricKey.Builder connectionSymmetricKey = ProtoConnectionSecuring.ConnectionSymmetricKey.newBuilder();
connectionSymmetricKey.setSymmetricKey(ByteString.copyFrom(encryption));
RequestWrapper requestWrapper = new RequestWrapper(2, connectionSymmetricKey);
try {
RequestQueue.sendRequest(requestWrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
After receiving response from the server, use HandlerResponse for reading the message.
At this class, we know automatically that it is necessary to decrypt the codes before reading the messages. Then we send byteArray to the HelperUnpackMessage.
After fetching the actionId in this class, we find intended name by it at the Lookup Table.
Notice: during naming the classes that are exist as Response in LookupTable, it is necessary that the class name be the same with the name in the LookupTable.
We create dynamically a sample of response class by instanceResponseClass method for recievinf response. Then using received ByteArray from the server that is now divided to ActionId and ProtoObject, invite the existing constructor and amount it.
As a result of this, after receiving any response, the message is sending to HelperUnpackMessage automatically and there, amounting and inviting given received class. So we can see all receiving responses from the server in Response classes.
ProtoConnectionSecuring.ConnectionSymmetricKeyResponse.Builder builder = (ProtoConnectionSecuring.ConnectionSymmetricKeyResponse.Builder) message;
ProtoConnectionSecuring.ConnectionSymmetricKeyResponse.Status status = builder.getStatus();
int statusNumber = status.getNumber();
if (statusNumber == Config.REJECT) {
WebSocketClient.getInstance().disconnect();
} else if (statusNumber == Config.ACCEPT) {
G.isSecure = true;
G.ivSize = builder.getSymmetricIvSize();
String sm = builder.getSymmetricMethod();
G.symmetricMethod = sm.split("-")[2];
}
The Global variables are set in G class. Sent messages are encrypted by symmetricKey.
ivSize is used for iv and sent message Separation.
isSecure stands for security detection.
lookupMap ActionId stands for maintaining list and response classes name.
in this page,there are general setting for example the amount of delay for TimeOut as well as server adress and other settings.