Skip to content

Instantly share code, notes, and snippets.

@mht mht/client.cpp
Last active May 11, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.