Java network programming from zero to explore 01 of the TCP / IP and Socket

  Recently completed several simpler projects, some days loose,  and finally stole a point of leisure time in 996 years , thinking about what to study study more, right? Console logs a common thing that catches my eye ( Nie Yuan ah ):  

        

  (FIG SpringBoot used to output the log log4j, LoggingLevel: Debug, JDK version 1.8 )

  The reason for this phenomenon may be, Mybatis in the implementation of the interface method, instantiate multiple Preparedstatement, NIO enabled different threads, but which, Huh?! Yes, NIO out for a while !!! IO ( days ! which ) after querying the network data and found that:

  In JDK 1.4 in the original I / O package and NIO has been well integrated. java.io. * have to re-implement NIO-based, so it can now take advantage of some of the features of the NIO. For example, java.io. * package classes method comprising reading and writing data in blocks, which makes it even more in the stream-oriented system, the processing speed will be faster. [Quote from: IBM official tutorial]

  In short, today's IO basically integrated with the NIO, in testing for some individual read and write operations, the version can be seen today in no way inferior speed IO NIO. So here, will log there NIO IO and that there is, both assisted each other with respect to the fast course NIO IO refers,  NIO more than the following characteristics: dispersibility and aggregation read, file locking, asynchronous IO network, high concurrency !!!

  Driven by the spirit of some of obsessive-compulsive disorder, I began this long journey of exploration of Java network programming. The road is long Come, my friends, before the trip together! What if I walked in the exploration detour welcome comments correct me !!! in this, the salted fish greatly appreciated !!! 

Java Network Programming

Transmission Control Protocol (TCP, Transmission Control Protocol)

  Network programming , means to write a program running on a plurality of devices, these devices are connected through a network.

  In J2SE specification, the java.net API encapsulates the low-level communication details, for developers who focus on problem-solving rather than communicate the details it provides support for two common network protocols:. TCP and UDP.

    

  Here we focus on understanding the TCP and TCP / IP

  The following information comes from the degree of your mother:

  Transmission Control Protocol (TCP, Transmission Control Protocol) is a transport protocol to provide reliable end to end on a byte stream unreliable network specifically designed. TCP layer to the application layer gateway for transmitting transmission data stream represented by 8-bit bytes, and the TCP data stream partitioned into segments of suitable length (typically by the data link layer of the network connection computer limiting the maximum transmission unit (MTU) in). After the result of TCP packets to the IP layer, by it through the network packet to the TCP layer entity receiving end. To ensure TCP packet loss does not occur, give each packet a sequence number, but also ensures that the serial number sequentially transmitted to the receiving end of the packet reception entity. Then the receiving side has successfully received packet entity sends back a corresponding acknowledgment (the ACK); If the sender entity within a reasonable round-trip time (RTT) acknowledgment is not received, then the corresponding data packet is assumed to have been will be lost retransmission. TCP checksum with a function to check if data has an error; checksum is calculated for transmission and reception.

  In conclusion, it is shown below (TCP protocol provides reliable connectivity services, the use of three-way handshake to establish a connection): 

  

  更加形象的表述就像是A到B家串门的情景, A先要通知B自己要去串门, 而B接受到这个消息后, 就发个消息回复A说: "六点有空你来吧,等不急啦!"  然后A也回复. "好嘞! 六点我就到!诶嘿嘿!!!"  最后, 六点A到了B家. 

IP ( 因特网互联协议, Internet Protocol )

  以下资料来源度娘:

  IP层接收由更低层(网络接口层,例如以太网设备驱动程序)发来的数据包,并把该数据包发送到更高层——TCP或UDP层;相反,IP层也把从TCP或UDP层接收来的数据包传送到更低层。IP数据包是不可靠的,因为IP并没有做任何事情来确认数据包是按顺序发送的或者没有被破坏。IP数据包中含有发送它的主机的地址(源地址)和接收它的主机的地址(目的地址)。

TCP / IP

 

OSI参考模型

 

Socket ( 套接字 )

  套接字使用TCP提供了两台计算机之间的通信机制。 客户端程序创建一个套接字,并尝试连接服务器的套接字。当连接建立时,服务器会创建一个 Socket 对象。客户端和服务器现在可以通过对 Socket 对象的写入和读取来进行通信。java.net.Socket 类代表一个套接字,并且 java.net.ServerSocket 类为服务器程序提供了一种来监听客户端,并与他们建立连接的机制。

 

 

  

Guess you like

Origin www.cnblogs.com/sansheng93/p/11246495.html