Last active
July 31, 2024 20:00
-
-
Save mht/f98fd3deeffed226fb4e8b2479e87834 to your computer and use it in GitHub Desktop.
JUCE InterprocessConnection Demo : Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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