Network Programming Overview
Network communication is a process of exchanging the data of two devices through a computer network. Network programming is an act of writing software to realize network communication.
Cangjie provides developers with basic network programming functions. Its standard library allows users to utilize the socket package in the std module to implement network communication at the transport layer.
Transport layer protocols are classified into unreliable transport protocols and reliable transport protocols, which are abstracted as DatagramSocket and StreamSocket in Cangjie. A common unreliable transport protocol is UDP and a common reliable transport protocol is TCP. They are respectively abstracted as UDPSocket and TcpSocket in Cangjie. In addition, Cangjie supports the Unix Domain protocol at the transport layer, enabling its communication in both reliable and unreliable transport modes.
A common application layer protocol is the HTTP protocol, which is widely used in developing web apps. Among the multiple HTTP protocol versions, Cangjie supports versions such as HTTP/1.1 and HTTP/2.0.
Besides, Cangjie abstracts WebSocket, an application layer protocol that contributes to a higher communication efficiency between the web server and the client, as a WebSocket object and supports the upgrade from HTTP to WebSocket.
It is worth noting that Cangjie's network programming adopts a blocking mode. The blocked Cangjie threads release the system thread. Therefore, the system thread is not blocked.