Java basics-network programming (UDP programming) and basic udp
UDP Programming
TCP index operations must establish reliable connections, which will definitely waste a lot of system performance. To reduce this overhead, another transmission protocol-UDP, unreliable connectio
1. UDP protocol to send data and receive dataThe UDP protocol sends the data: • Create a Socket object on the sending side • Create data and package the data • Call the Send method of the socket object to send the packet • Freeing resourcesThe UDP protocol receives data :• Create a Socket object on the receiving end• Create a packet, receive data (Receive
reception phenomenon ).Manipulating UDP in Java uses the Datagramsocket and Datagrampacket classes that are located under the java.net package in the JDK, making it very easy to control user data packets for UDP program development.Use the Datagrampacket class in UDP development to wrap a message that needs to be sent
UDP Transport: For a non-connected protocol, unreliable, just send the application to the IP layer of the datagram packet sent out, there is no guarantee to send out the datagram packets can reach the destination. No longer the client and the server to establish a connection, there is no time-out retransmission mechanism, fast transmission is its advantages. It is like sending a letter and putting it in a mailbox bucket, neither ensuring that the lett
Original: http://www.javacodegeeks.com/2014/07/9- Differences-between-tcp-and-udp-protocol-java-network-interview-question.html?utm_source=tuicool tcp and UDP two transport layer protocols, which are widely used in the Internet to send data between one host to another. A good understanding of how TCP and UDP works is e
achieve.
The UDP network programming also obtains the good support in the Java language, because it does not need to establish the special connection and so on in the transmission data the process, therefore the implementation structure which in the Java API design and the TCP method is not very same. Of course, the class that needs to be used is included in the
Java Support for UDPThe UDP protocol provides a service that differs from the TCP protocol's end-to-end service, which is non-connected and is unreliable, and UDP sockets do not need to be connected before they are used. In fact, the UDP protocol only implements two functions:
The port is added on the basis of
Java UDP Socket programming and javaudpsocket ProgrammingUDP protocol
The services provided by UDP protocol are different from the end-to-end services provided by TCP protocol. It is non-connection oriented and is an unreliable protocol. UDP sockets do not need to be connected before use. In fact,
Java TCP/UDP socket programming process summary, udpsocket
Recently I learned a little bit about java socket programming. Although the overall process is not very complicated, it is worth summing up.Socket
A Socket is an abstraction for the network. An application can read and write data on the network. Just like using a file handler to write data to a storage de
This article illustrates the Java approach to implement UDP protocol based on socket service. Share to everyone for your reference. Specifically as follows:
Example 1:
Receive class:
Package Com.socket.demo;
Import java.io.IOException;
Import Java.net.DatagramPacket;
Import Java.net.DatagramSocket; public class Udpreceivedemo {public static void main (string[] args) throws ioexception{System.out.p
Protocols that can be used in Java communication include TCP protocol and UDP protocolUDP Protocol ConceptsThe full name of the UDP protocol is the User Datagram Protocol, which is used in the network as the TCP protocol for processing packets, but it is a non-connected protocol. In the OSI model, the fourth layer, the transport layer, is in the upper layer of th
Java method for implementing UDP based on socket Service
This example describes how Java implements UDP based on the socket service. Share it with you for your reference. The details are as follows:
Example 1:
Receiving class:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
reliability. Here is the recommended book "TCP/IP detailed", divided into three volumes.TCP/IP modelThe TCP/IP model consists of four levels:Application LayerTransport LayerNetwork layerNetwork interfaceThe correspondence between TCP/IP and the OSI Reference Model: network classes in the JDKThrough the classes in the java.net package, Java programs can communicate over the Internet using TCP or UDP proto
Java Network Programming (2) InetAddress class and udp protocol, inetaddressudpInetAddress class
JDK provides the java.net package for developing network applications. The classes and interfaces under this package are almost all network programming services.
InetAddress: the object used to describe the IP address
The InetAddress class does not provide a constructor,
Instead, a static method is provided to o
Datagrampacket (Str.getbytes (), Str.length (), Inetaddress.getbyname ("localhost"), 9000); All information is saved using BUF System.out.println ("Send message. ");d S.send (DP);//Send information out ds.close ();}};Client:Import java.net.DatagramPacket; import java.net.DatagramSocket;p ublic class udpclient{public static void Main (String Args[]) throws exception{//all exceptions throw datagramsocket ds = NULL;//define object to receive datagram byte[] buf = new byte[1024];//Open space to rec
Java UDP network programming is implemented mainly through the Datagramsocket and Datagrampacket two classes, the following is an example program,The server listens on UDP 2000 ports and prints the received long type valuesThe client then gets a long value by entering it and sends it to the server
Server:/**//* Coding by NYZHL *Import java.net. * ;Import java.io.
What is a UDP protocol
The full name of the UDP protocol is the user datagram, which is used in the network as a TCP protocol for processing packets. In the OSI model, at layer fourth, the transport layer, is at the upper level of the IP protocol. UDP has the disadvantage of not providing datagram grouping, assembling and sorting packets, that is, when a message
In some Java programming, we often involve the use of UDP protocol, so today we will elaborate on the use of UDP protocol in Java. First, you need to understand the basic concepts and significance of UDP.
What is UDP?
The full nam
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 that will be sent is encapsulated into the packet//string str= "UDP transport demo. Go "; BufferedReader bufr=new BufferedReader (New InputStreamReader (system.in));//keyboard in
In the use of 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 pr
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.