summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/SocketClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'client/Piztor/src/com/macaroon/piztor/SocketClient.java')
-rw-r--r--client/Piztor/src/com/macaroon/piztor/SocketClient.java91
1 files changed, 84 insertions, 7 deletions
diff --git a/client/Piztor/src/com/macaroon/piztor/SocketClient.java b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
index 58b20c7..befe7fa 100644
--- a/client/Piztor/src/com/macaroon/piztor/SocketClient.java
+++ b/client/Piztor/src/com/macaroon/piztor/SocketClient.java
@@ -2,6 +2,7 @@ package com.macaroon.piztor;
import java.io.DataInputStream;
import java.io.DataOutputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -29,6 +30,8 @@ public class SocketClient {
static final int Logout =4;
static final int StartPush =5;
static final int SendMessage =6;
+ static final int SetMarker =7;
+ static final int SetPassword =8;
static final int ClosePush =-5;
@@ -39,7 +42,11 @@ public class SocketClient {
static final int GroupID =5;
static final int Latitude =6;
static final int Longitude =7;
+ static final int Level =8;
+ static final int PasswordFailed =5;
+ static final int ServerFetchFailed =4;
+ static final int LevelFailed =3;
static final int StatusFailed = 2;
static final int TimeOut = 1;
static final int Success = 0;
@@ -50,6 +57,7 @@ public class SocketClient {
client = new Socket();
client.connect(new InetSocketAddress(site,port), retime);
client.setSoTimeout(retime);
+ //client.setTcpNoDelay(true);
} catch (UnknownHostException e) {
e.printStackTrace();
throw e;
@@ -187,6 +195,52 @@ public class SocketClient {
pos+=ByteLength;
out.write(b);
break;
+ case SetMarker:
+ ReqSetMarker rsm = (ReqSetMarker) req;
+ len = IntLength+ByteLength+TokenLength+(rsm.uname).length()+ByteLength+DoubleLength+DoubleLength+IntLength;
+ b = new byte[len];
+ Convert.write(b,Convert.intToBytes(len),pos);
+ pos+=IntLength;
+ b[pos] = (byte) tmp;
+ pos+=ByteLength;
+ Convert.write(b,Convert.hexStringToBytes(rsm.token),pos);
+ pos+=TokenLength;
+ Convert.write(b,(rsm.uname).getBytes(),pos);
+ pos+=(rsm.uname).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,Convert.doubleToBytes(rsm.latitude),pos);
+ pos+=DoubleLength;
+ Convert.write(b,Convert.doubleToBytes(rsm.longitude),pos);
+ pos+=DoubleLength;
+ Convert.write(b,Convert.intToBytes(rsm.deadline),pos);
+ pos+=IntLength;
+ out.write(b);
+ break;
+ case SetPassword:
+ ReqSetPassword rsp = (ReqSetPassword) req;
+ len = IntLength+ByteLength+TokenLength+(rsp.uname).length()+ByteLength+(rsp.oldpassword).length()+ByteLength+(rsp.newpassword).length()+ByteLength;
+ b = new byte[len];
+ Convert.write(b,Convert.intToBytes(len),pos);
+ pos+=IntLength;
+ b[pos] = (byte) tmp;
+ pos+=ByteLength;
+ Convert.write(b,Convert.hexStringToBytes(rsp.token),pos);
+ pos+=TokenLength;
+ Convert.write(b,(rsp.uname).getBytes(),pos);
+ pos+=(rsp.uname).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,(rsp.oldpassword).getBytes(),pos);
+ pos+=(rsp.oldpassword).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ Convert.write(b,(rsp.newpassword).getBytes(),pos);
+ pos+=(rsp.newpassword).length();
+ b[pos] = 0;
+ pos+=ByteLength;
+ out.write(b);
+ break;
}
out.flush();
DataInputStream in = new DataInputStream(client.getInputStream());
@@ -195,6 +249,8 @@ public class SocketClient {
int type = in.readUnsignedByte();
int status = in.readUnsignedByte();
if(status == 1) return StatusFailed;
+ if(status == 2) return LevelFailed;
+ if(status == 3) return PasswordFailed;
switch (type) {
case Login:
byte[] buffer = new byte[32];
@@ -202,13 +258,13 @@ public class SocketClient {
String tk = Convert.byteToHexString(buffer);
outlen-=(IntLength+ByteLength+TokenLength+ByteLength);
int cnt = 0;
- int uid =0,s =0;
+ int uid =0,s =0,l =0;
String uname ="",nname ="";
double lat =0.0,lot =0.0;
RGroup rg = null;
int i = 0;
byte[] bu = new byte[200];
- while(cnt < 7) {
+ while(cnt < 8) {
int typ = in.readUnsignedByte();
outlen-=ByteLength;
switch(typ){
@@ -262,14 +318,17 @@ public class SocketClient {
lot = in.readDouble();
outlen-=DoubleLength;
break;
+ case Level:
+ l = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
}
cnt++;
}
- RUserInfo r = new RUserInfo(uid,uname,nname,lat,lot,rg,s);
+ RUserInfo r = new RUserInfo(uid,uname,nname,lat,lot,rg,s,l);
in.readUnsignedByte();
outlen-=ByteLength;
int number =0;
- System.out.println("read "+ outlen);
Vector<RGroup> vrg = new Vector<RGroup>();
while(outlen > 1) {
int com = in.readUnsignedByte();
@@ -297,7 +356,7 @@ public class SocketClient {
break;
case UserInfo:
outlen-=(IntLength+ByteLength+ByteLength);
- int uid1 =0,s1 =0;
+ int uid1 =0,s1 =0,l1 =0;
String uname1 ="",nname1 ="";
double lat1 =0.0,lot1 =0.0;
RGroup rg1 = null;
@@ -307,7 +366,7 @@ public class SocketClient {
int n = 0;
while(outlen > 0) {
int tmpcnt =0;
- while(tmpcnt < 7) {
+ while(tmpcnt < 8) {
int typ = in.readUnsignedByte();
outlen-=ByteLength;
switch(typ){
@@ -361,12 +420,16 @@ public class SocketClient {
lot1 = in.readDouble();
outlen-=DoubleLength;
break;
+ case Level:
+ l1 = in.readUnsignedByte();
+ outlen-=ByteLength;
+ break;
}
tmpcnt++;
}
in.readUnsignedByte();
outlen-=ByteLength;
- v.add(new RUserInfo(uid1,uname1,nname1,lat1,lot1,rg1,s1));
+ v.add(new RUserInfo(uid1,uname1,nname1,lat1,lot1,rg1,s1,l1));
n++;
}
msg.obj = new ResUserInfo(n,v);
@@ -391,12 +454,26 @@ public class SocketClient {
msg.what = SendMessage;
recall.sendMessage(msg);
break;
+ case SetMarker:
+ msg.obj = new ResSetMarker();
+ msg.what = SetMarker;
+ recall.sendMessage(msg);
+ break;
+ case SetPassword:
+ msg.obj = new ResSetPassword();
+ msg.what = SetPassword;
+ recall.sendMessage(msg);
+ break;
}
return Success;
} catch (SocketTimeoutException e){
e.printStackTrace();
return TimeOut;
+ } catch (EOFException e) {
+ e.printStackTrace();
+ //return ServerFetchFailed;
+ throw e;
} catch (IOException e) {
e.printStackTrace();
throw e;