In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how Java realizes the function of chat room based on UDP. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Project structure
Data.java
Package udp;import java.net.InetAddress;public class data {InetAddress Address; int Port; public InetAddress getAddress () {return Address;} public void setAddress (InetAddress address) {Address = address;} public int getPort () {return Port;} public void setPort (int port) {Port = port;}} server side
Server.java
Package udp;import java.io.IOException;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.net.InetAddress;import java.net.SocketException;import java.util.ArrayList;public class Server {DatagramSocket socket = null; ArrayList client; public Server () {try {socket = new DatagramSocket (8888);} catch (SocketException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} client = new ArrayList () } public void sprinter () {try {while (true) {byte [] buf = new byte [3000]; / / packets receiving data DatagramPacket packet = new DatagramPacket (buf,buf.length); socket.receive (packet); / / address InetAddress clientAddress = packet.getAddress (); / / port number int clientPort = packet.getPort (); data d = new data (); d.setAddress (clientAddress) D.setPort (clientPort); int iTun0; / / determine whether there is a client for (; I) sending new messages in the client collection.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.