ソース・プログラム
成り行きでいじっていたので、examples ディレクトリに作ってしまいましたw
O@HP8:~/f77_zmq-master/examples$ gfortran -g -O2 -Wall -Wno-unused -fopenmp test.f ../travis_ci/lib/libzmq.so libf77zmq.a -lzmq
include file のために、固定形式にしたので 72 桁制限があります。
program server
implicit none
include 'f77_zmq.h'
integer(ZMQ_PTR) :: context
integer(ZMQ_PTR) :: socket
character(len = :), allocatable :: id, raw, http_response
integer :: rc, id_size, iraw_size
character(len = *), parameter :: CRLF = achar(13) // achar(10)
allocate (character(len = 256):: id, raw)
http_response = 'HTTP/1.0 200 OK' // CRLF //
& 'Content-Type: text/html' // CRLF //
& CRLF //
& '<!DOCTYPE html>' // CRLF //
& '<html>' // CRLF //
& '<head>' // CRLF //
& '<title>Fortran ZMQ http server</title>' // CRLF //
& '</head>' // CRLF //
& '<body>' // CRLF //
& '<h1>Fortran ZMQ http server </h1>' // CRLF //
& '<p>Make Fortran Great Again!</p>' // CRLF //
& '</body>' // CRLF //
& '</html>'
context = f77_zmq_ctx_new()
socket = f77_zmq_socket(context, ZMQ_STREAM)
rc = f77_zmq_bind(socket, 'tcp://*:8080')
if (rc /= 0) stop 'Initialization error!'
do
id_size = f77_zmq_recv(socket, id, 256, 0)
if (id_size <= 0) stop 'id_size error!'
do
iraw_size = f77_zmq_recv(socket, raw, 256, 0)
if (iraw_size < 0) stop 'raw_size error!'
if (iraw_size == 256) cycle
exit
end do
rc = f77_zmq_send(socket, id, id_size, ZMQ_SNDMORE)
rc = f77_zmq_send(socket, http_response,
& len(http_response), 0)
rc = f77_zmq_send (socket, id, id_size, ZMQ_SNDMORE)
rc = f77_zmq_send (socket, 0, 0, 0)
end do
rc = f77_zmq_close(socket)
rc = f77_zmq_ctx_destroy(context)
end program server