Skip to content

Instantly share code, notes, and snippets.

@gfdac
Forked from mht/client.cpp
Created March 20, 2021 23:47
Show Gist options
  • Save gfdac/4c066840830547b2e18b507e1f06448e to your computer and use it in GitHub Desktop.
Save gfdac/4c066840830547b2e18b507e1f06448e 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