3.19 complement

Source: Internet
Author: User

Socket programming all, TCP/IP

One, TCP/IP communication, must have an IP address, must have the same socket (socket)
Steps:
1, addressing positioning:
Locate the host by IP address
Find the program by port (port number) (0-65535)
To view the port number of the host: cmd Netstat-ano
SQL Port number: 3306
Our own: after 8080
Native IP 127.0.0.1


2. Communication (Protocol)
TCP/IP contains:
TCP Reliable (three-time handshake) B can receive, B is received, B returns information to a
TUP unreliable, stateless, fast, video is generally used in this


Socket sockets
The socket application accesses TCP/IP calls

Socket Programming:
①, server-side:
1, set up a port to monitor the server
ServerSocket Server = new ServerSocket (8080);
2. Ready to explain customer service request: wait-Prepare
Socket socket = server.accept ();
3. Create an input stream:
BufferedReader br = new Buff. (New InputS. R.. (Socket.getinputstream));
PrintWriter pw = new PrintWriter (Socket.getoutputstream (), true);
4. Close the stream, close the socket, close the server
Br.close (); Socket.close ();p w.colse ();

②, customer service side: Less the first step ServerSocket
1. Send a request to the server
Socket socket = new Socket ("127.0.0.1", 8080);
2. Create an input/output stream:
BufferedReader br = new Bu. R.. (New InputS. R (Socket.getinputstream))
3, close the flow, socket,server

3.19 complement

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.