diff options
author | Teddy <[email protected]> | 2013-08-25 17:55:34 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2013-08-25 17:55:34 +0800 |
commit | f4d0989ae888bc2f83f0bc09cc826f7c79b1b6b5 (patch) | |
tree | 79c9fbb49a5a857c56843cef01b032e3430aa085 /client/Socket-demo/SocketClient.java | |
parent | f74999631c4f83a0c8532d6b7adb348dcd5d5205 (diff) | |
parent | 0a76dad753ed88a7575c2aafdd068ef6caa7247f (diff) |
Merge branch 'master' of github.com:Determinant/piztor
Diffstat (limited to 'client/Socket-demo/SocketClient.java')
-rw-r--r-- | client/Socket-demo/SocketClient.java | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/client/Socket-demo/SocketClient.java b/client/Socket-demo/SocketClient.java deleted file mode 100644 index df42484..0000000 --- a/client/Socket-demo/SocketClient.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.example.test; - - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.Socket; -import java.net.UnknownHostException; - -public class SocketClient { - - static Socket client; - - public SocketClient(String site, int port)throws UnknownHostException,IOException{ - try{ - client = new Socket(site,port); - }catch (UnknownHostException e){ - throw e; - }catch (IOException e){ - throw e; - } - } - - public Myrespond sendMsg(Myrequest req)throws IOException{ - try{ - DataOutputStream out = new DataOutputStream(client.getOutputStream()); - int tmp = (Integer) req.contain.get(0); - switch(tmp){ - case 0: - String id = (String) req.contain.get(1); - String pass = (String) req.contain.get(2); - out.writeUTF(id); - out.writeUTF(pass); - break; - case 1: - int tk1 = (Integer) req.contain.get(1); - int acc = (Integer) req.contain.get(2); - String mess = (String) req.contain.get(3); - out.writeInt(tk1); - out.writeInt(acc); - out.writeUTF(mess); - break; - case 2: - int tk2 = (Integer) req.contain.get(1); - double slot = (Double) req.contain.get(2); - double slat = (Double) req.contain.get(3); - out.writeInt(tk2); - out.writeDouble(slot); - out.writeDouble(slat); - break; - case 3: - int tk3 = (Integer) req.contain.get(1); - int gid = (Integer) req.contain.get(2); - out.writeInt(tk3); - out.writeInt(gid); - break; - } - out.flush(); - client.shutdownOutput(); - DataInputStream in = new DataInputStream(client.getInputStream()); - int type = in.readUnsignedByte(); - Myrespond r = new Myrespond(); - switch(type){ - case 0: - int id = in.readInt(); - int status = in.readUnsignedByte(); - r.contain.add(0); - r.contain.add(id); - r.contain.add(status); - break; - case 1: - r.contain.add(1); - //reserved - break; - case 2: - r.contain.add(2); - //reserved - break; - case 3: - int n = in.readInt(); - r.contain.add(3); - r.contain.add(n); - for(int i=1;i<=n;i++) - { - int tid = in.readInt(); - double lot = in.readDouble(); - double lat = in.readDouble(); - r.contain.add(tid); - r.contain.add(lot); - r.contain.add(lat); - } - break; - } - return r; - }catch(IOException e){ - throw e; - } - } - public void closeSocket(){ - try{ - client.close(); - }catch(IOException e){ - e.printStackTrace(); - } - } - -} |