📄 sserverthread.java
字号:
import java.io.*;
import java.net.*;
/**
*
* Server uses this class to communicate with connected client.
* Its main task is use s_parser() to parse user's request and transact it.<p>
* The requests include:
* <ul>
* <li>register_b: Transact register,see Sregister
* <li>signin_b: Transact signin, see Ssignin
* <li>requsers_b: Search registed user, see Srequsers
* <li>reqsignature_b: Look over online user's himself/herself signature, see Ssignature's req()
* <li>modsignature_b: Modify online user's himself/herself signature, see Ssignature's mod()
* </ul>
* <p>
* 2005.8.12<p>
* @version 0.1.2
* @author Daxin Tian
*
*
*/
public class SserverThread extends Thread{
/**
* Whether stop this thread.
*/
boolean stop_sSocket=false;
/**
* Point to the socket which connect to the JIDX Client.
*/
Socket ss;
/**
* The XML message sent by JIDX Client.
*/
String s_in=null;
/**
* Socket ss's DataInputStream.
*/
DataInputStream s_dis=null;
/**
* Socket ss's DataOutputStream.
*/
DataOutputStream s_dos=null;
XMLParser xp=new XMLParser();
/**
* Transact register request.
*/
Sregister s_reg;
/**
* Transact signin request.
*/
Ssignin s_signin;
/**
* Transact search registered client request.
*/
Srequsers s_requsers;
/**
* Transact look for or modify signature request.
*/
Ssignature s_signature;
/**
*
* @param s The socket is created by ServerSocket's accept().It will be used to communicate
* with the connected user.
*/
SserverThread(Socket s)
{
ss=s;
try
{
s_dis=new DataInputStream(ss.getInputStream());
s_dos=new DataOutputStream(ss.getOutputStream());
}
catch(IOException e)
{
}
//System.out.println("sserverThread constructor is ok");
}
/**
* The thread persists to reading connected user's request.
*/
public void run()
{
while(!stop_sSocket)
{
try
{
s_in=s_dis.readUTF();
//System.out.println(s_in);
s_parser();
}
catch(IOException e)
{
//System.out.println("error:"+e);
if(xp.name_s!=null)
{
new ScloseSocket(xp.name_s);
}
break;
}
}
}
/**
* The main task of server is performed by this function. It uses XMLParser to
* parse user's request and perform it.
*
*/
public void s_parser()
{
xp.in=new StringBufferInputStream(s_in);
xp.parser();
if(xp.register_b)
{
xp.register_b=false;
s_reg=new Sregister(xp.name_s,xp.password_s,xp.ips_s);
if(s_reg.register())
{
//System.out.println("register ok");
try
{
s_reg.backok(1,s_reg.info);
s_dos.writeUTF(s_reg.ok.c_sb.toString());
//System.out.println("send server register info");
}
catch(IOException e)
{
}
}
else
{
//System.out.println("register wrong");
try
{
s_reg.backerr(1,s_reg.info);
s_dos.writeUTF(s_reg.err.c_sb.toString());
}
catch(IOException e)
{
}
stop_sSocket=true;
}
}
if(xp.signin_b)
{
xp.signin_b=false;
s_signin=new Ssignin(xp.name_s,xp.password_s,xp.ips_s);
if(s_signin.signin())
{
//System.out.println("signin ok");
try
{
s_signin.backok(2,s_signin.info);
s_dos.writeUTF(s_signin.ok.c_sb.toString());
//System.out.println("send client signin info");
}
catch(IOException e)
{
}
}
else
{
//System.out.println("signin wrong");
try
{
s_signin.backerr(2,s_signin.info);
s_dos.writeUTF(s_signin.err.c_sb.toString());
}
catch(IOException e)
{
}
stop_sSocket=true;
}
}
if(xp.requsers_b)
{
xp.requsers_b=false;
//System.out.println("req users:"+xp.requsers_s);
s_requsers=new Srequsers(xp.requsers_s,s_dis,s_dos);
s_requsers.req();
xp.requsers_s=null;
}
if(xp.reqsignature_b)
{
xp.reqsignature_b=false;
//System.out.println("req sig:"+xp.reqsig_name_s);
s_signature=new Ssignature(xp.reqsig_name_s,s_dis,s_dos);
s_signature.req();
xp.reqsig_name_s=null;
}
if(xp.modsignature_b)
{
xp.modsignature_b=false;
s_signature=new Ssignature(xp.modsig_name_s,s_dis,s_dos);
s_signature.mod(xp.modsig_s);
xp.modsig_name_s=null;
}
if(xp.modpassword_b)
{
xp.modpassword_b=false;
new Spassword(xp.modpassword_name_s,xp.oldpassword_s,xp.newpassword_s,s_dis,s_dos);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -