|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果你学习的是市场营销,是销售,也许参加大课堂的学习会更合适,因为你的工作能力中有个基础就是搭建自己的人脉,谈天室|成绩这个谈天室是用java写的,个中一部分的源代码是如许的,可是调试运转不了,还请列位年夜侠指导:importjava.awt.event.*;importjava.net.*;importjava.io.*;importjava.util.*;importjavax.swing.Timer;publicclassAppServerimplementsRunnable{ServerSocketserver;SocketfromClient;ThreadserverThread;publicAppServer(){System.out.println("FunChatserverstart......");try{server=newServerSocket(1001);serverThread=newThread(this);serverThread.start();}catch(Exceptione){System.out.println("cannotstartthethread:"+e);}}//endofAppServerpublicstaticvoidmain(Stringargs[]){newAppServer();}publicvoidrun(){try{while(true){fromClient=server.accept();Connectcon=newConnect(fromClient);}}catch(Exceptione){System.out.println("cannotlistentotheclient"+e);}//endofcatch}//endofrun}//endofAppServerclassConnect{ObjectOutputStreamstreamToClient;intctr=0;BufferedReaderstreamFromClient;staticVectorvector;staticVectorvctrList;Stringmessage="";staticStringstr=newString("UsrList");static{vector=newVector(1,1);vctrList=newVector(1,1);vctrList.addElement((String)str);}intverify(Stringmesg){try{RandomAccessFieldRAS=newRandomAccessFile("UsrPwd.txt","r");inti=0;Stingstr="";while((RAS.getFilePointer())!=(RAS.length())){str=RAS.readLine();if(str.equals(mesg)){ctr=1;break;}}RAS.close();}catch(Exceptione){System.out.print("ExceptionOccurred:"+e);}returnctr;}intcheckFile(Stringmesg){intchk=1;try{RandomAccessFileRS=newRandomAccessFile("UsrPwd.txt","r");inti=0;Stringstr="";Stringcolon=newString(":");intindex=((String)mesg).lastIndexof(colon);StringuserName=(String)mesg.substring(0,index);while((RS.getFukeOiubter())!=(int)(RS.length())){str=RS.readLine();intindex1=((String)str).lastIndexof(colon);StringusrName=(String)str.substring(0,index1);if(usrName.equals(userName)){chk=0;break;}}}catch(Exceptione){System.out.print("ExceptionOccurred:"+e);}returnchk;}publicConnect(SocketinFromClient){Stringmsg="";Stringmesg="";try{streamFromClient=newBufferedReader(newInputStreamReader(inFromClient.getInputStream()));streamToClient=newObjectOutputStream(inFromClient.getOutputStream());msg=streamFromClient.rreadLine();if((msg.equals("FromTimer"))){streamToClient.writeObject.writeObject(vector);streamToClient.writeObject(vctrList);}elseif(msg.equals("LoginInfo")){msg=streamFromClient.readLine();intver=verify(msg);if(ver==1){Stringcolon=newString(":");intindex=((String)msg).lastIndexOf(colon);StringuserName=(String)msg.substring(0,index);if(!(vctrList.indexOf((String)userName)>0)){streamToClient.writeObject("Welcome");vctrList.addElement((String)userName);}}else{streamToClient.writeObject("Ligindenied");}}elseif(msg.equals("RegisterInfo")){msg=streamFromClient.readLine();intret=checkFile(msg);if(ret==0)streamToClient.writeObject("UserExists");if(ret==1){FileOutputStreamout=newFileOutputStream("UsrPwd.txt",true);PrintStreamp=newPrintStream(out);p.println();p.println(msg);p.close();streamToClient.writeObject("Registered");}}elseif(msg.equals("UserLogout"));{StringremUser=streamFromClient.readLine();booleanb=vctrList.removeElement((String)remUser);}else{message=message+msg;vector.addElement((String)message);streamToClient.writeObject(vector);}}catch(Exceptione){System.out.println("cannotgettheclientstreamconnect"+e);}finally{try{inFromClient.close();}catch(IOExceptione){System.out.println("ExceptionOccurred:"+e);}}}}
多谢指点,其实我对.net和ruby也不是很了解,对与java也只是刚起步的阶段,只是在学习中有了点想法就写出来了,现在俺本科还没毕业,所以对大型项目基本上也没有什么经验。 |
|