Package COM. jiDi. service; import Java. io. bufferedinputstream; import Java. io. bufferedreader; import Java. io. file; import Java. io. fileinputstream; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. io. objectoutputstream; import Java. io. outputstream; import Java. io. printwriter; import Java. io. serializable; import java.net. inetaddress; import java.net. socket; import java.net. unknownhostexception; import javax. persistence. entity; import Org. dom4j. document; import Org. dom4j. element; import Orm. employee; import Orm. employeedao; public class employeeclient implements serializable {Package COM. jiDi. service; import Java. io. bufferedinputstream; import Java. io. bufferedreader; import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. io. objectinputstream; import Java. io. objectoutputstream; import Java. io. outputstreamwriter; import Java. io. printwriter; imp ORT Java. io. reader; import Java. io. serializable; import java.net. serversocket; import java.net. socket; import Java. util. list; import Org. dom4j. document; import Org. dom4j. export enthelper; import Org. dom4j. element; import Orm. employee; import Orm. employeedao; public class employeeservice implements serializable {public employeedao = new employeedao (); Public void saveemployee (employee Employee) {EMP Loyeedao. save (employee);} public static void main (string [] ARGs) throws exception {employeeservice = new employeeservice ();} public employeeservice () throws exception {// �� service�� servicesocket �� ϊ 6666666666try {serversocket Server = new serversocket (6666); system. out. println ("~ "); // Fig socket = server. accept (); // response string line; bufferedreader is = new bufferedreader (New inputstreamreader (socket. getinputstream (); printwriter OS = new printwriter (socket. getoutputstream (); bufferedreader sin = new bufferedreader (New inputstreamreader (system. in); system. out. println ("client:" + is. readline (); line = sin. readline (); While (! Line. equals ("bye") {OS. println (line); OS. flush (); system. out. println ("client:" + is. readline (); line = sin. readline ();} OS. close (); // close the socket output stream is. close (); // close socket input stream socket. close (); // close socketserver. close (); // close serversocketobjecttoxmlutil. objectxmldecoder ("D: \ v. XML ");} catch (filenotfoundexception e) {// todo auto-generated dffcatch blocke. printstacktrace ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace () ;}} public list <employee> getemployeelist () {return employeedao. findall ();} // public void employeetransitionxml (list) {// document = incluenthelper. createdocument (); // file = new file ("D:/SS. XML "); // element titleelement = document. addelement ("employesslist"); // For (INT I = 0; I <list. size (); I ++) {// employee EMP = (employee) list. get (I); // element = titleelement. addelement ("employee"); // element idelement = element. addelement ("ID"); // idelement. settext ("" + EMP. GETID (); // element nameelement = element. addelement ("name"); // nameelement. settext (EMP. getname (); // element emailelement = element. addelement ("email"); // emailelement. settext (EMP. getemail (); // element organizationelement = element. addelement ("Organization"); // organizationelement. settext (EMP. getorganization (); // element mobileelement = element. addelement ("mobile"); // mobileelement. settext (EMP. getmobile (); // element telelement = element. addelement ("tel"); // telelement. settext (EMP. gettel (); // element addresselement = element. addelement ("Address"); // addresselement. settext (EMP. getaddress (); // element memoelement = element. addelement ("memo"); // memoelement. settext (EMP. getmemo (); // element tempelement = element. addelement ("Temp"); // tempelement. settext ("" + EMP. gettemp (); // element limit_timeelement = element. addelement ("limit_time"); // limit_timeelement.settext ("" + EMP. getlimittime (); // element statuselement = element. addelement ("status"); // statuselement. settext (EMP. getstatus (); // element login_nameelement = element. addelement ("login_name"); // login_nameelement.settext (EMP. getloginname (); // element passwordelement = element. addelement ("password"); // passwordelement. settext (EMP. getPassword (); // element group_idelement = element. addelement ("group_id"); // group_idelement.settext ("" + EMP. getgroupid (); // element change_passwordelement = element //. addelement ("change_password"); // change_passwordelement.settext ("" + EMP. getchangepassword (); // element create_dateelement = element. addelement ("create_date"); // create_dateelement.settext ("" + EMP. getcreatedate (); // element create_ipelement = element. addelement ("create_ip"); // create_ipelement.settext ("" + EMP. getcreateip (); //} // try {// outputstreamwriter out = new outputstreamwriter (// new fileoutputstream (File); // document. write (out); // out. close (); //} catch (filenotfoundexception e) {// todo auto-generated Catch Block // E. printstacktrace (); //} catch (ioexception e) {// todo auto-generated Catch Block // E. printstacktrace ();//}//}}
Public static void main (string [] ARGs) throws exception {employeeclient clinetserver = new employeeclient ();} public employeeclient () throws exception {try {employee Employee = new employee (); employee. setloginname ("liujie"); employee. setemail ("liujie@163.com"); objecttoxmlutil. objectxmlencoder (employee,
"D: \ v. XML "); Socket socket = new socket (" 127.0.0.1 ", 6666); printwriter OS = new printwriter (socket. getoutputstream (); bufferedreader is = new bufferedreader (New inputstreamreader (socket. getinputstream (); OS. println (1); system. out. println ("1"); OS. flush (); OS. close ();
// Close the socket output stream is. close (); // close socket input stream socket. close (); // close socket} catch (exception e) {// todo: handle exception }}}
Package COM. jiDi. service; import Java. io. bufferedinputstream; import Java. io. bufferedreader; import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstreamreader; import Java. io. objectinputstream; import Java. io. objectoutputstream; import Java. io. outputstreamwriter; import Java. io. printwriter; imp ORT Java. io. reader; import Java. io. serializable; import java.net. serversocket; import java.net. socket; import Java. util. list; import Org. dom4j. document; import Org. dom4j. export enthelper; import Org. dom4j. element; import Orm. employee; import Orm. employeedao; public class employeeservice implements serializable {public employeedao = new employeedao (); Public void saveemployee (employee Employee) {EMP Loyeedao. save (employee);} public static void main (string [] ARGs) throws exception {employeeservice = new employeeservice ();} public employeeservice () throws exception {// �� service�� servicesocket �� ϊ 6666666666try {serversocket Server = new serversocket (6666); system. out. println ("~ "); // Fig socket = server. accept (); // response string line; bufferedreader is = new bufferedreader (New inputstreamreader (socket. getinputstream (); printwriter OS = new printwriter (socket. getoutputstream (); bufferedreader sin = new bufferedreader (New inputstreamreader (system. in); system. out. println ("client:" + is. readline (); line = sin. readline (); While (! Line. equals ("bye") {OS. println (line); OS. flush (); system. out. println ("client:" + is. readline (); line = sin. readline ();} OS. close (); // close the socket output stream is. close (); // close socket input stream socket. close (); // close socketserver. close (); // close serversocketobjecttoxmlutil. objectxmldecoder ("D: \ v. XML ");} catch (filenotfoundexception e) {// todo auto-generated dffcatch blocke. printstacktrace ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}}}