Hello kind people,
I am trying to make 2 PCs to communicate via JUCE InterProcessConnection and DatagramSocket classes over the local network. Lets name the computers A and B.
I need to send data from A to B, so I set up a InterProcessConnectionServer on the B side and wait for a connection with beginWaitingForSocket on defined port and IP Address. On the A side I try to connect to that socket and it works. By that I have managed to send some messages from A to B. Now the thing is that I want to send my data as UDP packets,connectionless,from A to B but using the other port,not the same one as for interprocess. When I press the button on A side to send data, it first sends a message to B side to let it know to expect a data to come. On B side in messageReceived() it recognizes that message, binds its DatagramSocket to the correct port and calls a function that will wait for socket to be ready to read, read the data,process it and repeat it as long as the data is incoming. But the problem is that it constantly crashes somewhere in memory where I cannot reach by debugger. I’ll share some code below:
—Setting up the server on B side—
class Server :public InterprocessConnectionServer { public: InterprocessConnection* createConnectionObject() override { return process; } void addProcess(InterprocessConnection* p) { process = p; } private: InterprocessConnection* process; };
Then, I create an instance of Server in my Component which is derived from InterProcessConnection. In its constructor I have:
server.addProcess(this); server.beginWaitingForSocket(5001, "127.0.0.1");
Then,
void MainComponent::messageReceived(const MemoryBlock &message) { String receivedMessage = message.toString(); if (receivedMessage.contains("connectUDP")) { if(udpSocket.getBoundPort()!=5000) udpSocket.bindToPort(5000, "127.0.0.1"); connected = true; receiveDataAndLog(); } }//<--------sometimes crashes here on debugging for writing access violation
Where,
void MainComponent::receiveDataAndLog() { if (connected) { unsigned char* msg_data; int bytesReceived = 0; String ipAddress; int sendport; if (udpSocket.waitUntilReady(true, 1000)) { bytesReceived = udpSocket.read(msg_data, packetByteLength, false, ipAddress, sendport); if (bytesReceived > 0) { //..do something } } } }
On A side I use write function of its DatagramSocket and send it to the port and ip address of B side, data arrives, but then it crashes.
Is this a possible way to do something like this, did I set up the IPC server correctly? I have tried creating IPC with callbacksOnMessageThread set to both true and false but neither worked.
I have limited knowledge in this area, everything is still pretty new to me so any tips regarding socket communication is more than welcome. If you would like me to share more info I would gladly do it!
Thanks in advance,
Cila

