- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to create a TCP/IP client and server in FORTRAN. Socket programming does seem to be supported based on some code snippets I've seen. But I can't find anything in the documentation that tells me how to do it. For example, I know I need to call WSAGetLastError() for error-handling. But the compiler doesn't know what that is. Are there include files and libraries or modules I need to include in my project?
And, does anyone have any complete examples? Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://www.sockaddr.com/ExampleSourceCode.html
For using Winsock with Fortran, you should USE WSOCK32 or USE WS2_32 to get the interfaces correct (those two are almost the same -- I'm not sure which is the "current" version). In addition, you should link your application with ws2_32.lib.
Here's a code sample in Fortran. Apparently, it dates sometime before the above modules were written, so it does a lot of "do-it-yourself" declarations (i.e. its own module Winsock).
Hope that helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The module ws2_32.f90 delivered with Intel Visual Fortran provides you with the INTERFACEs to call those socket functions. Put
USE IFWIN
in the header of your program and those INTERFACEs are available. To open a streaming TCP socket you might code:
FUNCTION mySocket( iErrorCode ) RESULT(iSocket)USE IFWIN
INTEGER(POINTER_LEN) :: iSocketiSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
IF ( iSocket == INVALID_SOCKET ) THEN! ... handle erroriSocket = -1
ELSE! ok
! ...
END IF
END FUNCTION
Hope this helps.
Jrg Kuthe

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page