O (≧ mouth ≦) o just hit a lot of content, the results forget the network disconnected, unable to automatically save the draft. The results of the release of the contents have been lost. The air died, and did not write.Today is about the Java EE, speak quickly, mainly on the focus or is not the same as SE, just a bit, almost jumped over, let us see ppt ... (content not dropped) ...I made a simple chat room
The example of this article for you to share the Java Group chat function, for your reference, the specific content as follows
Java support for TCP protocols:the--> java.net package defines two classes of serversocket and sockets, respectively, for both the server and client sides of a two-way connection.--> Client Classes define Clients
Package com.drag
This example for you to share the Java implementation of Tcpsocket chat room function of the relevant code for your reference, the specific content as follows
1.tcpserver.java
Import java.net.*;
Import java.io.*;
Import java.util.*;
Import java.util.concurrent.*;
public class tcpserver{private static final int serverport = 8888;
Private ServerSocket MyServer = null;
Private list
2.tcpclient.
I reviewed Java for a day. In the evening, I wrote a heartchat 0.1 program to enable multiple clients to chat with each other.CodeAs follows:
Import Java. Io .* ; Import Java.net .* ; Import Java. util .* ; Public Class Heartserver { /* * Member variable debut */ List New Arraylist (); /** * This is the
() + "\ n"); Ta_send.settext ("");} catch (Exception ex) {System.out.println (ex);}}}); /try {ip = inetaddress.getbyname (STR_IP); socket = new Datagramsocket (this.myport); socket1 = new Datagramsocket ( This.myport + 1); Socket2 = new Datagramsocket (This.myport + 2); Timer timer = new timer ();//timer, flush Receive Message timer.schedule (new mytimertask_receive (), 0, +); while (Socket!=null) {try {// byte filetipbuf[] = new BYTe[256];//prevents the file name word from being too long (up t
Originally this homework I want to make a graphical interface, but the reality is that I understand test instructions wrong, and then lost the initial interest, or the program into a function of the correct but "UI" unfriendly console, but no matter how, the development of the pre-graphic interface is very rewarding, after all, to tell the truth, It is not easy to make a tangible color of Java, and with the help of visual plugins Windowsbuilder, the p
Oh, with Java package Development socket connection, is very simple ~ ~ ~Dailyadviceserver.javaImportJava.io.*;Importjava.net.*; Public classdailyadviceserver {string[] advicelist= {"Take smaller Bites", "Go for the tight Jeans", "code well written, beggar to Old", "you might want to rethink"}; Public voidGo () {Try{serversocket Serversock=NewServerSocket (4242); while(true) {Socket sock=serversock.accept (); PrintWriter writer=NewPrintWriter (Sock.
(); }; } @Override Public voidrun () {Try{//Note: to include a while loop, a socket closed exception occurs if the try is in the while loop while(connected) {String str=Dis.readutf (); System.out.println (str); for(intI=0;i) {Client C=Clients.get (i); C.send (str); } //For (iterator//Client C=it.next ();//method Two, not advisable, with synchronous lock//c.send (str);// } //it
");/*** the server sends a confirmation message */scannerscan=newscanner ( system.in); Stringsendmsg=sCan.next ();p w.println (sendmsg);p W.flush ();}} /*** client * @throws IOException* @throws unknownhostexception */publicstaticvoidclient () throwsUnknownHostException, IOEXCEPTION{//uses the socket to make a request to the specified machine and port socketsocket=newsocket ("192.168.1.101", 9999);/***2. The client receives a welcome message from the server and sends the data *///through the soc
,bytes.length); - //accepting packets with sockets - recevicesocket.receive (datagrampacket); - //get the IP address of the sending end -inetaddress IP =datagrampacket.getaddress (); in //converts the received message to a string -String rec =NewString (Datagrampacket.getdata ()); toSystem.out.println (ip.gethostaddress () + "message Sent:" +rec); + -}Catch(SocketException e) { the e.printstacktrace (); *}Catch(IOException e) { $ e.printstacktrace
Blog
Community
Homepage
New essay
Contact
Management
Subscription
Post-42-0 comments-72 differences between java. util. Date and java. SQL. Date and the application of java. util. Date are used in addition to SQL statements.
Java. SQL. Date is used for SQL statements.
As described in the summary, the frequent need to deploy the program to the test machine at the time of the tune-up, it is inconvenient to debug. The previous practice is to print information in the program to track, but this method is very limited, because often can not be located in the problem at once, need to constantly modify the program to print the statement, constantly restart the application, which takes a lot of time and effort. Therefore, i
Accelerate Java application development speed 2-accelerate project debugging startup speed and java application development
In the previous article on improving the speed of Spring/Hibernate, we mainly used some techniques to increase the startup speed, or we could not do hot deployment or hot replacement of the class.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.