Java-network programming (1): data transmission between the client and the server

Source: Internet
Author: User

Currently, for bean sprouts I have just started with network programming, the most intuitive understanding of network programming is data transmission between some clients and a server. The specifics are complex, but I will learn them later.

Today, I learned that the client and server can be connected through socket and datagramsocket. They correspond to TCP and UDP respectively.

Datagrampacket class:

The datagrampacket class is a data packet.

A datagram packet is used to deliver a connectionless package. Each packet is routed only from one machine to another based on the information contained in the packet. Multiple packages sent from one machine to another may have different routes or may arrive in different order. The package delivery is not guaranteed. I think this is a complicated abstract understanding. I personally simply understood it as a package with a byte buffer, the package contains the recipient's address, name, and other information (specifically, the port number, IP address, and so on ).

The mongoramsocket class uses the receive and send methods to send and receive data packets, that is, to send and receive specific objects of the mongorampacket class, so as to implement the client and server. Data transmission.

Socket class:

The Socket socket corresponds to the TCP protocol. In addition to the differences between TCP and UDP, the socket and datagrampacket are different. In terms of data transmission, the socket uses two streams: inputstream and outputstream. For example:

Socket socket = new socket ("cuishen.iteye.com", 80); inputstream in = socket. getinputstream (); outputstream out = socket. getoutputstream ();

These three statements are equivalent to connecting two pipes, One inbound and the other outbound, between the client and the server.

Today I am the first to get started with the concept of network programming, so I understand what is superficial. But it is a good start. If any, please advise.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.