# \[SOLVED\] Help on IPC-Sockets needed

**URL:** https://forum.juce.com/t/solved-help-on-ipc-sockets-needed/3978
**Category:** General JUCE discussion
**Created:** [June 3, 2009, 3:48pm UTC](https://forum.juce.com/t/solved-help-on-ipc-sockets-needed/3978 "2009-06-03T15:48:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Myke](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Myke](https://forum.juce.com/u/Myke)
#### Post date: [June 3, 2009, 3:48pm UTC](https://forum.juce.com/t/solved-help-on-ipc-sockets-needed/3978/1 "2009-06-03T15:48:24Z")

</div>

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:

```auto
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:

```auto
	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:

```auto
	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

```auto

```

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

```auto
...
           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.

---

<div class="post-metadata">

### Author: ![Myke](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Myke](https://forum.juce.com/u/Myke)
#### Post date: [June 4, 2009, 8:10am UTC](https://forum.juce.com/t/solved-help-on-ipc-sockets-needed/3978/2 "2009-06-04T08:10:46Z")

</div>

[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:

```auto

```

---

<div class="post-metadata">

### Author: ![vishvesh](https://avatars.discourse-cdn.com/v4/letter/v/85e7bf/32.png) [@vishvesh](https://forum.juce.com/u/vishvesh)
#### Post date: [June 4, 2009, 9:19am UTC](https://forum.juce.com/t/solved-help-on-ipc-sockets-needed/3978/3 "2009-06-04T09:19:40Z")

</div>

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