Skip to content

Instantly share code, notes, and snippets.

@mht
Last active March 20, 2021 23:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mht/f98fd3deeffed226fb4e8b2479e87834 to your computer and use it in GitHub Desktop.
Save mht/f98fd3deeffed226fb4e8b2479e87834 to your computer and use it in GitHub Desktop.
JUCE InterprocessConnection Demo : Client
const int kPortNumber = 52713;
class Connection : public InterprocessConnection
{
public:
Connection()
: InterprocessConnection(false, 15)
{
}
void connectionMade() override
{
printf("Connection made\n");
}
void connectionLost() override
{
printf("Connection lost\n");
}
void messageReceived(const MemoryBlock& msg) override
{
const auto str = msg.toString();
printf("From server: %s\n", str.toRawUTF8());
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Connection);
};
int main (int argc, char* argv[])
{
printf("\n");
std::unique_ptr<Connection> client(new Connection());
client->connectToSocket("localhost", kPortNumber, 5000);
if (client->isConnected()) {
printf("Connected\n");
String msg("713");
MemoryBlock mb;
mb.append(msg.toRawUTF8(), msg.length());
client->sendMessage(mb);
client->disconnect();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment