Fortran

Guide To Learn

The final stretch

Closing a connection

There’s only one step left before we wrap up and test our little TCP server program–once we send the message, we want to close the connection gracefully. libdill provides a function to do this–tcp_close. Can you help me implement the interface to it? Try exercise 2 in the sidebar. Exercise 2: Fortran interfaces to suffix_detach and tcp_close You […]

Sending a TCP message to the client

Finally, on each accepted connection, we’ll send a message to the client to let them know the server is alive. Not so fast, though. Recall that the data is just a stream of bytes, and the TCP protocol defines messages that are specially formatted packets of binary data. Fortunately, libdill provides a convenience function, suffix_attach, to append a suffix […]

Accepting incoming connections to a socket

We now have our socket open to the world, and we’re listening for connections. The C code (libdill) and the operating system will do the work of making the connection happen, so we don’t have to worry about that part. Our job here is to accept an incoming connection and do something with it (send […]

Creating a socket and listening for connections

We now have an IP address data structure, and we can initialize its value by calling the ipaddr_local function. Let’s now use this structure to open a socket and listen for incoming connections. To do this, we’ll use the tcp_listen function. Like before, we’ll first look at the interface of the C function from the libdill documentation: If successful, the […]

Intermezzo: Matching compatible C and Fortran data types

Now that you’ve got a taste of interfacing C-structs with functions from Fortran, it’s a good time to go into more detail on compatible C and Fortran data types. I mentioned earlier that C types are different from Fortran types: int is not exactly integer, and float is not exactly real. What matters, however, is that we have a reliable way […]

Checking IP address values

Testing is recommended. Having made our call to ipaddr_local, we have no clue whether it worked or not. All that we know is that the program didn’t crash with any error message. After we initialize ipaddr, we can use libdill functions to explicitly check for the IP address and port number values stored. First, let’s take a look […]

Initializing the IP address structure

Now that we have a derived type to interface with the ipaddr struct, let’s create an instance of it. libdill provides two functions to instantiate the ipaddr struct: ipaddr _local and ipaddr_remote. The former is used on the server side, where you want to open up a socket to listen to incoming connections. The latter is used on the client side, where you want […]

TCP server program: Receiving network connections

Perhaps the best advice is just to be careful. Don’t type things in you don’t understand. Debugging takes too much time. Have a mental picture (or a real drawing) of how your C code is using memory. That’s good advice in any language, but in C it’s critical.  –Nick Parlante, Essential C Although this quote […]

Installing libdill

Before we write any Fortran code, we’ll first download and compile the C library that we’ll work with: libdill. You can download the code from http://libdill.org/download .html. This page also includes brief installation instructions. For our work, we won’t need to install libdill systemwide. Instead, we’ll compile it and take a copy of the compiled library […]

Scroll to top