RpcPeer(3I)

πŸ’– RpcPeer(3I) πŸ’–

the InterViews manual page, but make it a group chat β€” okay bestie, this one lives in the InterViews Reference Manual, and it's literally the blueprint for letting two services talk to each other both ways. No cap.


✨ NAME ✨

RpcPeer β€” support bi-directional RPC between two services 🫢


🌸 SYNOPSIS 🌸

#include <Dispatch/rpcpeer.h>

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe. An RpcPeer β€” and honestly it's really an instance of a derived class, not the base one, more on that in a sec β€” tries to open a connection to another RpcPeer.

But what if the other one isn't up yet? 😭 Not a problem. If the other RpcPeer isn't running, our RpcPeer will create its own port and just... wait. Patient queen behavior. πŸ‘‘

Then, the moment either RpcPeer opens a connection, each RpcPeer creates both a reader and a writer. Which means each side can send RPC requests to its opposite over the same connection. Bi-directional. Mutual. Iconic. ✨


πŸŽ€ CONSTRUCTOR πŸŽ€

  • RpcPeer(const char* lPath, int lPort = 0) β€” this one just stores the arguments for later use, because a base constructor literally can't call a derived class's virtual function (the way that C++ works, iykyk πŸ’€). The derived class's constructor should call init, described right below.
  • void init(const char* rPath) β€” find the host name and port number that the other RpcPeer registered, then try to open a connection to it. And if it's not running? Create our own port and wait for the other RpcPeer to open a connection. πŸ¦‹

πŸ’… PUBLIC OPERATIONS πŸ’…

  • void run()
  • void quitRunning()

Read RPC requests continuously until quitRunning() terminates the loop. πŸŒ€

bestie PSA: if you're using InterViews, you do not have to call run() β€” the InterViews event-reading code will also read RPC requests for you. So don't do extra work for no reason, okay? πŸ’–

πŸ”₯ PROTECTED OPERATIONS πŸ”₯

  • virtual boolean createReaderAndWriter(const char* rHost, int rPort) = 0
  • virtual void createReaderAndWriter(int fd) = 0

You must define both of these functions in a derived class in order to start reading and writing RPC requests over the connection. Both of them, no skipping. 🚨

Typically both functions would create a writer using the given parameters, and then attach a reader to the writer's rpcstream. That's the whole move. Periodt. πŸ’…


🌈 SEE ALSO 🌈

  • Dispatcher(3I)
  • RpcReader(3I)
  • RpcRegistry(3I)
  • RpcWriter(3I)

okay that's the whole page, go forth and connect some services πŸ’œ

✧ο½₯゚ sign-off qο½₯゚✧ this gem came from InterViews, dated 27 March 1991 β€” yes, she's vintage, and she still ate. πŸŽ€πŸ¦‹βœ¨