Computer network programming: Difference between revisions

Content deleted Content added
m Undid edits by 87.251.25.103 (talk) to last version by AnnaBSP
 
(116 intermediate revisions by 76 users not shown)
Line 1:
{{Short description|Writing computer programs with networking capability}}
In [[computing]], '''network programming''', essentially identical to ''[[Internet socket|socket]] programming'' or ''[[client–server]] programming'', involves writing [[computer programs]] that communicate with other programs across a [[computer network]]. The program or process initiating the communication is called a [[client (computing)|client]] process, and the program waiting for the communication to be initiated is the [[Server (computing)|server]] process. The client and server processes together form a [[distributed system]]. The communication between the client and server process may either be [[connection-oriented]] (such as an established [[Transmission Control Protocol|TCP]] [[virtual circuit]] or [[Session (computer science)|session]]), or [[connectionless]] (based on [[User Datagram Protocol|UDP]] datagrams).
{{one source|date=June 2013}}
 
{{For|similar terms referring to the hardware technologies committed to computer network programming |Computer network}}
A program that can act both as a client and a server is based on [[peer-to-peer]] communication.
 
'''Computer network programming''' involves writing [[computer programs]] that enable [[process (computing)|processes]] to communicate with each other across a [[computer network]].<ref>{{cite book| url=http://people.scs.carleton.ca/~lanthier/teaching/COMP1406/Notes/COMP1406_Ch12_NetworkProgramming.pdf | archive-url=https://web.archive.org/web/20200305163115/http://people.scs.carleton.ca/~lanthier/teaching/COMP1406/Notes/COMP1406_Ch12_NetworkProgramming.pdf | url-status=dead | archive-date=2020-03-05 | chapter=Chapter 12 - Network Programming | date=2017 | quote=Network Programming involves writing programs that communicate with other programs across a computer network. | title=COMP1406 }}</ref>
Sockets are usually implemented by an [[Application programming interface|API]] library such as [[Berkeley sockets]], first introduced in 1983. Most implementations are based on [[Berkeley sockets]], for example [[Winsock]], introduced in 1991. Other socket API implementations exist, such as the [[Streams (networking API)|STREAMS]]-based [[Transport Layer Interface]] (TLI).
 
== Connection-oriented and connectionless communications ==
These are examples of functions or methods typically provided by the API library:
 
* <code>socket()</code> creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.
Very generally, most of communications can be divided into [[Connection-oriented_communication|connection-oriented]], and [[Connectionless_communication|connectionless]]. Whether a communication is connection-oriented or connectionless, is defined by the [[Communications_protocol|communication protocol]], and not by {{nowr|[[application programming interface]] (API)}}. Examples of the connection-oriented protocols include {{nowr|[[Transmission Control Protocol]] (TCP)}} and {{nowr|[[Sequenced Packet Exchange]] (SPX)}}, and examples of connectionless protocols include {{nowr|[[User Datagram Protocol]] (UDP)}}, "raw IP", and {{nowr|[[Internetwork Packet Exchange]] (IPX)}}.
* <code>bind()</code> is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address.
 
* <code>listen()</code> is used on the server side, and causes a bound TCP socket to enter listening state.
== Clients and servers ==
* <code>connect()</code> is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.
{{main|client–server model}}
* <code>accept()</code> is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.
 
* <code>send()</code> and <code>recv()</code>, or <code>write()</code> and <code>read()</code>, or <code>recvfrom()</code> and <code>sendto()</code>, are used for sending and receiving data to/from a remote socket.
For connection-oriented communications, communication parties usually have different roles. One party is usually waiting for incoming connections; this party is usually referred to as "[[Server_(computing)|server]]". Another party is the one which initiates connection; this party is usually referred to as "[[Client_(computing)|client]]".
* <code>close()</code> causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.
 
For connectionless communications, one party ("server") is usually waiting for an incoming packet, and another party ("client") is usually understood as the one which sends an unsolicited [[Network_packet|packet]] to "server".
 
== Popular protocols and APIs ==
 
Network programming traditionally covers different layers of [[OSI_model|OSI/ISO model]] (most of application-level programming belongs to L4 and up). The table below contains some examples of popular protocols belonging to different OSI/ISO layers, and popular APIs for them.
 
{| class="wikitable"
! OSI/ISO Layer
! Protocol
! API
|-
| L3 (network)
| [[Internet Protocol|IP]]
| [[Raw socket]]
|-
| L4 (transport)
| [[Transmission Control Protocol|TCP]], [[User Datagram Protocol|UDP]], [[Stream Control Transmission Protocol |SCTP]]
| [[Berkeley Sockets]]
|-
| L5 (session)
| [[Transport Layer Security|TLS]]
| [[OpenSSL]]
|-
| L7 (application)
| [[HTTP]]
| Various
|}
 
== See also ==
* [[Inter- communication]] (IPC)
 
* [[Software-defined networking]]
==External links==
*[[Infrastructure as code]]
* [http://beej.us/guide/bgnet/ Beej's guide to network programming]
* [[Site reliability engineering]]
* http://www.kohala.com/start/preface.unpv12e.html
* [[DevOps]]
* http://java.sun.com/docs/books/tutorial/networking/overview/networking.html
* [http://lionel.textmalaysia.com/network-programming-for-python-pyqt4.html Network Programing For Python PyQt4]
 
== References ==
{{compu-prog-stub}}
* W. Richard Stevens: '''[[UNIX Network Programming]]''', Volume 1, Second Edition: Networking APIs: Sockets and XTI, Prentice Hall, 1998, {{ISBN|0-13-490012-X}}
 
{{reflist}}
[[Category:Computer networks engineering]]
[[Category:Computer programming]]
[[Category:Inter-process communication]]
 
[[mk:Computer network programming]]
[[ru:Программирование сетевых задач]]