× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi David,

<snip>
I want to create two RPG programs, both connected to the same external IP
address and port number and both sharing the same internal port number.
Specifically I want one program to be sending out over the port and I want a
different program to receive the tcp/ip packet(s) from the remote system in
response to the sent packet.

Is this possible, if so could you simply explain what needs to be done, and
finally can you reference me to any examples?
</snip>

You want to have two programs using the same outbound port number, talking
to the same remote (or local) port. Are they running in the same job? Are
they each aware of the work the other is doing?

If you have two programs running in the same job and both will be reading
writing to the same socket in an organised and predictable way then you can
simply pass the socket descriptor up/down the call stack. The descriptor is
simply an integer, but the system keeps track of what that integer
represents. Descriptors can represent any streamed data - files, sockets,
pipes, etc... So just pass the descriptor between your programs. If you want
to have two programs simultaneously connect to a remote (or local) server on
the same outbound port then you are out of luck. You can use the bind() API
to specify the outbound port, but I don't think you'd have much luck trying
to bind to the same port twice. This is the same as outbound ports - you
can't have more than one application listening on port 80. That'd be crazy.
Nobody would know who they were talking to and the applications on both ends
would steal each others data.

It is quite simple to get two programs to talk down the same socket - even
in separate jobs. I know you want one program to read and another to write,
but can you give us a little more about how you want to set it up? We can
then suggest possible architecture for your app.

<Ken said>
A TCP/IP socket is uniquely defined by the combination of the source IP
address, source port, target IP address, and target port. So you're not
going to be able to have two separate programs each opening its own socket
with the same IP addresses and ports. You're going to somehow share one
socket between the two programs. Don't ask me how to do that. The one socket
application I've written had all of the sending and receiving in one program
so the issue didn't arise.
</Ken said>

You're right about a socket being a unique connection between two ports, but
within your program the socket is represented by a descriptor - you can just
pass that to the other program. It is no different to one program opening a
stream file and calling another to read from it - you just pass the file
descriptor. You can even pass descriptors between jobs using the
givedescriptor() and takedescriptor() APIs. They are very easy to use. We
use them for a web back-end application on the iseries - one job acts as a
mini-webserver and listens on the port for data from our tomcat server. When
a request comes in it "gives" the descriptor to one of the worker jobs
running in the same sub-system. The worker job then processes the data.
performs all business functions, and passes the xml response back directly
to our tomcat server.


Cheers

Larry Ducie


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.