Source code: cxtable/core_comm/xClientNeg.java
1 package cxtable.core_comm;
2
3 import cxtable.xLineSplit;
4 import cxtable.peer.xClientContinual;
5
6
7 /*this class handles login negotiating for the client end of a connection...
8 once the actual socket has been connected..this handles negotiating
9 a real status with the other end...used for both connects to Registry and
10 connects to other peers*/
11
12
13 public class xClientNeg extends Thread implements xListener{
14 private final String _who = "xClientNeg";
15 private xLineSplit xls; private xClientContinual xclco;
16 private xClientConn xclient; private String mssg = "";
17 private String name,reg_id,serv_id;
18 private String my_ip,my_port;
19 private static final String[] key= new String[]{"<COMMAND>"};
20 public xClientNeg(xClientConn x, String nm, String r_k, xClientContinual xcc)
21 { reg_id=r_k;
22 my_ip=xcc.getIP();my_port=xcc.getPort();
23 name = nm; mssg = "<LOGIN><REG_ID>"+reg_id+"</REG_ID><IP>"+my_ip+"</IP><PORT>"+my_port+"</PORT><NAME>"+name+"</NAME></LOGIN>";
24 xclient = x; xclco = xcc;
25 xls = new xLineSplit();}
26
27 public void run()
28 {xclient.send(mssg);}
29
30 public String who(){
31 return _who;}
32
33 public void read(String s)
34 {
35 String[] cmd = xls.split("COMMAND",s);
36
37 if (cmd.length < 1 ) {
38 return;}
39
40 for (int i=0; i<cmd.length; i++)
41 {
42
43 if (cmd[i].equals("LOGIN")==true)
44 {
45 new Thread(this).start();
46 return;
47 }
48 if (cmd[i].equals("LOGGED")==true)
49 {
50 System.out.println("Logged in as "+name);
51 xclient.offListen(this);
52 xclco.add(xclient);
53 xclient.setClientID(reg_id);
54
55 }
56 }
57 }
58
59 public boolean readAll()
60 {return false;}
61
62 public String[] readKeys()
63 {return key;
64 }
65
66 /*end*/
67
68 }