[SOLVED] Help on IPC-Sockets needed

Hey guys,

I’m trying to send string messages from one machine to another and i though InterprocessConnection[Server] is exactly the thing that does the job for me.

I’ve had a look at the Juce DEMO!'s Source Code as well, and it looked pretty straight forward to me, unfortunatelly i can’t get this working… (I got it working for NamedPipes, but now i need to send the messages from machine to machine and not from process to process on the same machine)

I’ve reduced my code to the following:

class DemoInterprocessConnection  : public InterprocessConnection
{
    int ourNumber;

    public:
        DemoInterprocessConnection():InterprocessConnection (true)
        {
            static int totalConnections = 0;
            ourNumber = ++totalConnections;
        }

        ~DemoInterprocessConnection()
        {
        }

        void connectionMade()
        {
			assert(false && "connectionMade");
			std::cout << "Connection #" << ourNumber << " - connection started" << std::endl;
        }

        void connectionLost()
        {
			assert(false && "connectionMade");
			std::cout << "COnnection #" << ourNumber << " - connection lost" << std::endl;
        }

        void messageReceived (const MemoryBlock& message)
        {
			assert(false && "connectionMade");
			std::cout << "Connection #" << ourNumber << " - message received: " << (const char*)message.toString() << std::endl;
        }
};

OwnedArray<DemoInterprocessConnection, CriticalSection> activeConnections;

class DemoInterprocessConnectionServer   : public InterprocessConnectionServer
{
    public:
        DemoInterprocessConnectionServer ()
        {
        }

        ~DemoInterprocessConnectionServer()
        {
        }

        InterprocessConnection* createConnectionObject()
        {
			std::cout << "createConnectionObject" << std::endl;
            DemoInterprocessConnection* newConnection = new DemoInterprocessConnection();

			activeConnections.add(newConnection);
			return newConnection;
        }
};

And on the Server-side (the side i wonna receive messages) i do:

	DemoInterprocessConnectionServer* server = new DemoInterprocessConnectionServer();
	res = server->beginWaitingForSocket(12345);
	
	for (int i = 0; i < 100; ++i) 
	{
		std::cout << "waited: " << i << "s" << std::endl;
		Sleep(1000);
	}
	return 0;

And on the Client-side (the side i wonna send messages) i do:

	DemoInterprocessConnectionServer* server = new DemoInterprocessConnectionServer();
	DemoInterprocessConnection* newConnection = new DemoInterprocessConnection();
		
	if (!newConnection->connectToSocket("192.168.5.147", 12345, 1000)) 
	{
		delete newConnection;
		newConnection = 0;

	}

	String text(T("MessageContent"));
	MemoryBlock messageData((const char*)text, text.length());

	for (int j = 0; j < 10; ++j) 
	{
		if (newConnection)
		{
			if (!newConnection->sendMessage(messageData)) {
				std::cout << "message could't get sent" << std::endl;
			} else {
				std::cout << "message should be sent" << std::endl;
			}
			Sleep(1000);
		}
	}

For now i’m executing both processes on the same machine, which runs Win XP as OS.

Both, the beginWaitingForSocket method and the connectToSocket method return true.
When the sendMessage is called still returns true, but both processes are caught by a jassert in juce_win32_thread.cpp in

which is called from: void InterprocessConnection::run()

...
           const int ready = socket->waitUntilReady (true, 0);

            if (ready < 0) {
                ...
            } else if (ready > 0) {
                ...
            }
            else
            {
                Thread::sleep (2);    <--- here
            }
...

BTW: I’m not running this in a juce Application. I just use these Classes in a win32 console application (which does some rendering stuff)

Anyone any idea what i’m doing wrong?

Thanks in advance!

Regards, Myke.

[quote=“Myke.”]Hey guys,

… bla bla bla …

BTW: I’m not running this in a juce Application. I just use these Classes in a win32 console application (which does some rendering stuff)

blaaa…
[/quote]

Problem solved:

Good on you, I was trying to generate the same assert. But failed :oops: