concept incoming connection in category fortran

appears as: incoming connections, n incoming connection, incoming connection
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

To get your feet wet with interfacing with C from Fortran, we’ll develop a minimal TCP client and server. We’ll start with an existing C library that’s easy to download and install and is well documented. One step at a time, we’ll write Fortran interfaces with C functions that we’ll use. With only several function calls, we’ll have a working TCP server running as a Fortran program and listening for incoming connections from anywhere in the world. We’ll wrap up the chapter by writing a small TCP client, so in the end we’ll have two Fortran programs talking to each other over the network.

Listing 11.7. The main server loop, which accepts the incoming connection, attaches the TCP suffix, sends a message, and closes the connection
language="fortran" linenumbering="unnumbered">do
  connection = tcp_accept(socket, addr_remote, -1_c_int64_t)
  call ipaddr_str(addr, address_string)
  print *, 'New connection from ' // trim(address_string)
  connection = suffix_attach(connection, TCP_SUFFIX, 2_c_size_t)
  rc = msend(connection, 'Hello' // c_null_char, 5_c_size_t, -1_c_int64_t)
  connection = suffix_detach(connection, -1_c_int64_t)
  rc = tcp_close(connection, -1_c_int64_t)
end do

That’s it! Our server will now accept an incoming connection, send a greeting message to the client, and close the connection.