When using the UDP protocol, we usually use other language tools to complete the work. So today we will mainly introduce the use of UDP protocol in Java. First, let's take a look at the basic concepts of UDP. The full name of UDP protocol is user datagram, which is used to p
will be sent encapsulated into the packet 4, the socket service via UDP to send data packets 5, close the socket service *///udpsocket service, Use the Datagramsocket object Datagramsocket ds=new datagramsocket (9999);//Listener port//The data to be sent is encapsulated in the packet//string str= "UDP transmission demo, go"; BufferedReader bufr=new BufferedReader (New InputStreamReader (system.in));//keybo
send, do not need to establish a connection in advance, do not need to return the package. Therefore, only need an IP and port, UDP can be sent to this port, as to whether the IP and port, or the recipient does not receive, UDP is no matter. So the most important thing in UDP is two classes, one is Datagramsocket, the other is Datagrampacket, the first one is si
(DP); } Catch(IOException e) {System.out.println ("Send failed:"); E.printstacktrace (); } /**4. Close Resources*/S.close (); }}Run the above Java program:Get the data in the Network Data Transceiver tool:Using socket programming to receive data over the UDP protocolUdprecv.java Packagecom. Train;ImportJava.net.DatagramPacket;ImportJava.net.DatagramSocket;//
In the last article we discussed the specific use of TCP and its differences with UDP, this time we talk about the actual application of Java network programming in UDP.
UDP Programming
UDP English User Datagram Protocol, Chinese meaning is User Datagram protocol. The
I implemented the Chat Room Group Chat window by complying with the TCP protocol ServerSocket and sockets in the Javase project chat room. At the same time, when introducing the OSI and TCP/IP reference Model, we also mentioned TCP and UDP (full name user Datagram Protocol, Subscriber Datagram Protocol).In general, the difference between TCP and UDP is:The basic difference between 1.TCP and
packet by the socket service's Receive method 4. With the unique functionality of the packet object, these different data are taken out and printed on the console 5. Close Resources */classudprece{ Public Static voidMain (string[] args)throwsexception{//1. Create UDP, set up endpointDatagramsocket ds=NewDatagramsocket (4567); //2. Define the packet to store byte[] buf=New byte[1024]; Datagrampacket DP=NewDatagrampacket (buf,buf.length); //3. D
Implementation of UDPThe two classes that implement the UDP protocol in Java are the Datagrampacket packet class and the Datagramsocket socket class .Unlike the TCP protocol implementation, it is:UDP socket Datagramsocket is a very simple concept compared to sockets and ServerSocket, and there is no connection meaning. sockets only need to know the local port on which the packet is listening and sending .Th
to find his destination.
Note: udp ports and tcp
"Full stack Java notes" is a can help you from Zeto long for the full stack of Java Engineer Series of notes. The author is called Mr. G,10 years Java research and development experience, has been in the digital, Aerospace Ins
classes under the Java.net package in JDK to conveniently control user data packets.Before describing them, you must understand the InetAddress class in the same location. InetAddress implements the Java. io. Serializable interface and does not allow inheritance. It is used to describe and package an Internet IP address and return the InetAddress instance in three ways:GetLocalhost (): returns the instance that encapsulates the local address.GetAllBy
Java UDP uses Socket for network chat (1), udpsocket
Author: Qing Dujun
Address: http://blog.csdn.net/qingdujun/article/details/39312065
This article demonstrates how to use Socket for network chat to enable the client to send messages to the server. When "886" is sent, the client is closed.
1) the client sends data to the server. If "886" is sent, the client is disabled.
2) The server keeps listening to p
Java Network Programming provides two types of protocols: TCP (Transmission Control Protocol) and UDP (Datagram protocol). TCP (transmission Control Protocol) is a reliable transport protocol that uses the "three-time handshake" side to establish a connection to ensure data reliability and security, while UDP (User Datagram PROTOCOL) protocol is an unreliable tra
Author: ChingOriginal address: http://blog.csdn.net/qingdujun/article/details/39300293The following shows a program that uses a client to send a message to the server, which is printed on the control Panel after it is received.1) client, send data to server2) server, after receiving the data, print it on the control PanelFirst, the client, the main steps:1) Create a UDP service. Through the Datagramsocket object.2) Create the data and encapsulate it i
There are generally two kinds of--tcp and UDP in network transmission mode. This article is for a brief look at how UDP is transmitted.What are the characteristics of UDP?1, for non-connected;2, for the message, and each message does not exceed 64KB;3, unreliable but efficient (do not establish a connection);4, support a pair of one or one-to-many, many-to-one, m
127.0.0.1 is the loop address for testing, equivalent to localhost native address, no network card, no DNS can be accessed.The port address is between 0~65535, where the port between 0~1023 is used for some well-known network services and applications, and the user's normal network application should use more than 1024 of the port.Network applications are basically TCP (Transmission Control Protocol Transmission Protocol) and UDP (User Datagram Protoc
No connection Communication UDPClient Packagecom.swift.test;Importjava.io.IOException;ImportJava.net.DatagramPacket;ImportJava.net.DatagramSocket;Importjava.net.InetAddress;ImportJava.util.Scanner;/*Write a Java program using UDP communication. Required: Gets the contents of the keyboard input. Sent to the server. After the server is received. Print the received content on the console client 1. Create a key
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.