The Janus Sockets product provides APIs for writing applications that use arbitrary protocols layered on top of the TCP/IP protocol. These APIs include low-level TCP/IP calls for communicating directly with the TCP/IP layer as well as higher-level APIs for using protocols such as HTTP (web requests) and SMTP (e-mail). The Janus Sockets product also provides Janus FTP Server, an FTP Server that can be used without any User Language coding at all (though it can be extended with User Language code), and Janus Telnet Server, a telnet/tn3270 server that can be used to access Model 204 directly from a PC-based 3270 emulator.
The following classes are provided with Janus Sockets:
The rest of this article provides an introduction to sockets. For links to all the Janus Sockets-specific topics, see Category:Janus Sockets.
Introduction to Sockets
The Janus family provides many different high-level mechanisms for accessing resources on the Internet and for communication between processes. Sometimes, however, systems require lower-level network communication: for example, when you want to write special-purpose back-end systems that retrieve information off the web without a browser, or systems that need to send e-mail or WAP protocol messages.
In client-server applications, the server provides some service, such as processing database queries or providing current stock quotes on demand. The client uses the service provided by the server, either displaying database query results to the user or making stock purchase recommendations to an investor. The communication that occurs between the client and the server must be reliable. That is, no data can be dropped, and it must arrive on either side in the same order in which the other sent it.
Transmission Control Protocol — the TCP part of TCP/IP — is the protocol that provides the reliable, point-to-point communication channel that client-server applications on the Internet use to communicate with each other. To communicate over TCP, a client program and a server program establish a connection to one another. Each program binds a socket to its end of the connection. To communicate, the client and the server each reads from and writes to the socket bound to the connection. The high-level communication interfaces — like Janus Web Server or Janus Open Server — rely on sockets for their communications, and Janus Sockets provides applications with direct access at the socket layer for custom applications.
What is a socket?
A socket is one end-point of a two-way communication link between two programs running on the network. It is also usefully thought of as a logical handle to such a link. Janus Sockets $functions or Socket object methods create and manage sockets to establish and communicate over the connection between a client program and a server program.
Or, alternatively, these same socket communication tasks are handled by the Janus Sockets object-oriented "helper" interfaces:
These interfaces are abstractions of the underlying $function and object method layers.
Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.
On the client-side, the client knows the hostname of the machine on which the server is running and the port number to which the server is connected (there are well-known default port numbers for specific services like ftp, telnet, HTTP, etc., so the client readily knows the port number).
So, for instance, the client might know that there is a web server running at port 80 at Sirius Software's mainframe. A client (here, a web browser) would connect to the machine specifying the host address and port, given as host.ipaddress:port in the browser's "Location" window:
And the web server running at port 80 would accept and respond to the client request.
When the server accepts a connection it assigns a socket to the connection. It needs a new socket to distinguish the connection from others being served from that port.
Note that the socket on the client side is not bound to the remote server port number. Rather, the client is assigned a port number local to the machine on which the client is running.
The client and server can now communicate by writing to or reading from their sockets.