RPG CLIENT ROLE
H DFTACTGRP(*NO) ACTGRP(*NEW)
D getservbyname PR * ExtProc('getservbyname')
D service_name * value options(*string)
D protocol_name * value options(*string)
D p_servent S *
D servent DS based(p_servent)
D s_name *
D s_aliases *
D s_port 10I 0
D s_proto *
D inet_addr PR 10U 0 ExtProc('inet_addr')
D address_str * value options(*string)
D INADDR_NONE C CONST(4294967295)
D inet_ntoa PR * ExtProc('inet_ntoa')
D internet_addr 10U 0 value
D p_hostent S *
D hostent DS Based(p_hostent)
D h_name *
D h_aliases *
D h_addrtype 10I 0
D h_length 10I 0
D h_addr_list *
D p_h_addr S * Based(h_addr_list)
D h_addr S 10U 0 Based(p_h_addr)
D gethostbyname PR * extproc('gethostbyname')
D host_name * value options(*string)
D socket PR 10I 0 ExtProc('socket')
D addr_family 10I 0 value
D type 10I 0 value
D protocol 10I 0 value
D AF_INET C CONST(2)
D SOCK_STREAM C CONST(1)
D IPPROTO_IP C CONST(0)
D connect PR 10I 0 ExtProc('connect')
D sock_desc 10I 0 value
D dest_addr * value
D addr_len 10I 0 value
D p_sockaddr S *
D sockaddr DS based(p_sockaddr)
D sa_family 5I 0
D sa_data 14A
D sockaddr_in DS based(p_sockaddr)
D sin_family 5I 0
D sin_port 5U 0
D sin_addr 10U 0
D sin_zero 8A
D send PR 10I 0 ExtProc('send')
D sock_desc 10I 0 value
D buffer * value
D buffer_len 10I 0 value
D flags 10I 0 value
D recv PR 10I 0 ExtProc('recv')
D sock_desc 10I 0 value
D buffer * value
D buffer_len 10I 0 value
D flags 10I 0 value
D close PR 10I 0 ExtProc('close')
D sock_desc 10I 0 value
D translate PR ExtPgm('QDCXLATE')
D length 5P 0 const
D data 32766A options(*varsize)
D table 10A const
D msg S 50A
D sock S 10I 0
D port S 5U 0
D addrlen S 10I 0
D ch S 1A
D host s 32A
D file s 32A
D IP s 10U 0
D p_Connto S *
D RC S 10I 0
D Request S 60A
D ReqLen S 10I 0
D RecBuf S 50A
D RecLen S 10I 0
C*************************************************
c eval *inlr = *on
C*************************************************
C* Change the host value to be equal with the
C* value of NT/2000 server where is running the
C* Visual Basic server program
C*************************************************
c eval host = '100.100.7.99'
C*************************************************
C* Change the port value to be equal with the
C* port value of Visual Basic server program
C*************************************************
c eval port = 1412
C*************************************************
C* Change the request value to be equal with the
C* data arrival value of Visual Basic server program
C*************************************************
c eval request = 'SalesForce'
C*************************************************
C* Test the existence of the host IP
C*************************************************
c eval IP = inet_addr(%trim(host))
c if IP = INADDR_NONE
c eval p_hostent = gethostbyname(%trim(host))
c if p_hostent = *NULL
c eval msg = 'Unable to find that host!'
c dsply msg
c return
c endif
c eval IP = h_addr
c endif
C*************************************************
C* Create a socket
C*************************************************
c eval sock = socket(AF_INET: SOCK_STREAM:
c IPPROTO_IP)
c if sock < 0
c eval msg = 'Error calling socket()!'
c dsply msg
c return
c endif
C*************************************************
C* Create a socket address structure that
C* describes the host and port we wanted to
C* connect to
C*************************************************
c eval addrlen = %size(sockaddr)
c alloc addrlen p_connto
c eval p_sockaddr = p_connto
c eval sin_family = AF_INET
c eval sin_addr = IP
c eval sin_port = port
c eval sin_zero = *ALLx'00'
C*************************************************
C* Connect to the requested host
C*************************************************
C if connect(sock: p_connto: addrlen) < 0
c eval msg = 'unable to connect to server!'
c dsply msg
c callp close(sock)
c return
c endif
C*************************************************
C* Translate the request to ASCII format
C*************************************************
c eval reqlen = %len(%trim(request))
c callp Translate(reqlen: request: 'QTCPASC')
C*************************************************
c* Send the request to the NT/2000 server
C*************************************************
c eval rc = send(sock: %addr(request): reqlen:0)
c if rc < reqlen
c callp close(sock)
c eval msg = 'Unable to send entire request!'
c dsply msg
c return
C else
c callp close(sock)
c eval msg = 'Message was send!'
c dsply msg
c return
c endif
VISUAL BASIC SERVER ROLE
In order to create the Visual Basic project start a new standard project, add the Microsoft Winsock Control to the toolbox, from the toolbox add a Winsock control to the existed form and give it the name Winsock. Then copy the source code to the form code area.
Option Explicit
Dim iport As Integer
Dim srequest As String
Private Sub Form_Load()
' The iport and srequest values must match the port and request values of RPG program
iport = 1412
srequest = "SalesForce"
On Error Resume Next
' start listening port on the assigned port
If Not App.PrevInstance = True Then
Winsock.LocalPort = iport
Winsock.Listen
Else
Unload Me
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Winsock.Close
End Sub
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next
If Winsock.State <> sckClosed Then Winsock.Close
Winsock.Accept requestID
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim sdata As String
Winsock.GetData sdata
If sdata = srequest Then
' If the iport and srequest values match the port and request values of RPG program
' then call the notepad application and reset listening
Shell "notepad.exe", vbMaximizedFocus
Winsock.Close
Winsock.LocalPort = iport
Winsock.Listen
End If
End Sub