Java Network protocol TCP and client/server generics

Source: Internet
Author: User
Tags file system implement mail client port number server port
Server | client | network

In network programming (also in other forms of communication, such as database programming), applications that use sockets are divided into two categories--client programs and server programs. You may be familiar with the "Client/server Programming" terminology, although the exact meaning of the term is not necessarily clear to you. The following example is a discussion of this topic.

1. Client/server Paradigm

The client/server paradigm divides the software into two categories--client programs and server programs. The client software initiates a connection and sends the request, while the server software listens for the connection and processes the request. In a UDP programming environment, no actual connection is established, and the UDP application can establish and receive requests on the same socket. In a TCP environment, a connection is established between two computers, and the client/server paradigm is relative.

When the software is a client or server, it defines the role strictly so that it is easier to adapt to the familiar thinking model. The software either initiates the request or processes the request. Switching between the two roles makes the system more complex. Even if a switch is allowed, the software program can only be a client at a particular time, and the other must be a server. If two are clients at the same time, there is no server processing request.

Client/server paradigm is an important theoretical concept, which is widely used in practical applications. There are also other communication models, such as the Peer-to-peer (peer to peer) model, in which each party can initiate communication. But the client/server concept is a more popular choice because it is simple and is used in most network programming.

2, the network client

The network client initiates the connection and typically handles network transactions. Server programs are used to implement client requests--clients do not need to implement server requests. Although the client is in control, there are still functions on the server side. The client can ask the server to delete all files from the local file system, but the server does not have to perform this task.

The network client talks to the server using a communication standard (that is, a network protocol) agreed by both parties. For example, the command group used by HTTP clients differs from the mail client, and the purpose is different. Connect HTTP to the mail server, or the mail client connects to the HTTP server, either an error message occurs or an error message that the client cannot understand. For this reason, a port number must be used as part of the protocol specification so that the client can locate the server. The Web server is typically running on port 80, and some other servers may be running on non-standard ports, and the custom of URLs is not to list ports, and it assumes that 80 ports are used.

3, network server

The role of the network server is to bind a particular port (which the client uses to locate the server) and to listen for new connections. Although the client is temporary and runs only when the user is selected, the server program must run uninterrupted (even if there are virtually no connected clients), expecting a client to need the service at some point. Server programs are often referenced as data adaptive monitor processes, using UNIX usage. It runs persistently, and typically starts when the host of the server program is started. Therefore, the server waits until a client establishes a connection to the server port. Some server programs can only handle a single connection at some point, and some other server programs may handle multiple connections simultaneously by using multithreading.

When the connection is started, the server obeys the client. It waits for the client to send the request and "faithfully" handles them (the server can respond to the error message, especially if the request violates some important protocol rules or a security risk). Some protocols, such as http/1.0, typically allow only one request per connection, while others (such as POP3) support a range of requests. The server can answer the client's request by sending a response or an error message. Learning a new network protocol (writing a client or server) is similar to learning a new language, except that the syntax changes. But typically, the number of commands is smaller, making things simpler. The behavior of the server is partly determined by the protocol and partly by the developer (some of the commands are optional and the server does not necessarily support them).



Related Article

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.