diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp
index 86e2a3bd69..a039bd91cd 100644
--- a/common/draw_frame.cpp
+++ b/common/draw_frame.cpp
@@ -132,6 +132,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
     KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
     m_galDisplayOptions( std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>() )
 {
+    m_socketServer        = nullptr;
     m_drawToolBar         = NULL;
     m_optionsToolBar      = NULL;
     m_auxiliaryToolBar    = NULL;
@@ -216,6 +217,13 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
 
 EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
 {
+    delete m_socketServer;
+    for( auto socket : m_sockets )
+    {
+        socket->Shutdown();
+        socket->Destroy();
+    }
+
     if( m_canvasTypeDirty )
         saveCanvasTypeSetting( m_canvasType );
 
diff --git a/common/eda_dde.cpp b/common/eda_dde.cpp
index afddd58d22..0d86d2f7a8 100644
--- a/common/eda_dde.cpp
+++ b/common/eda_dde.cpp
@@ -46,7 +46,7 @@ static char client_ipc_buffer[IPC_BUF_SIZE];
 
 /* Function to initialize a server socket
  */
-wxSocketServer* CreateServer( wxWindow* window, int service, bool local )
+void EDA_DRAW_FRAME::CreateServer( int service, bool local )
 {
     wxIPV4address addr;
 
@@ -57,16 +57,12 @@ wxSocketServer* CreateServer( wxWindow* window, int service, bool local )
     if( local )
         addr.Hostname( HOSTNAME );
 
-    wxSocketServer* server = new wxSocketServer( addr );
+    delete m_socketServer;
+    m_socketServer = new wxSocketServer( addr );
 
-    if( server )
-    {
-        server->SetNotify( wxSOCKET_CONNECTION_FLAG );
-        server->SetEventHandler( *window, ID_EDA_SOCKET_EVENT_SERV );
-        server->Notify( true );
-    }
-
-    return server;
+    m_socketServer->SetNotify( wxSOCKET_CONNECTION_FLAG );
+    m_socketServer->SetEventHandler( *this, ID_EDA_SOCKET_EVENT_SERV );
+    m_socketServer->Notify( true );
 }
 
 
@@ -106,17 +102,19 @@ void EDA_DRAW_FRAME::OnSockRequest( wxSocketEvent& evt )
  */
 void EDA_DRAW_FRAME::OnSockRequestServer( wxSocketEvent& evt )
 {
-    wxSocketBase*   sock2;
+    wxSocketBase*   socket;
     wxSocketServer* server = (wxSocketServer*) evt.GetSocket();
 
-    sock2 = server->Accept();
+    socket = server->Accept();
 
-    if( sock2 == NULL )
+    if( socket == NULL )
         return;
 
-    sock2->Notify( true );
-    sock2->SetEventHandler( *this, ID_EDA_SOCKET_EVENT );
-    sock2->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
+    m_sockets.push_back( socket );
+
+    socket->Notify( true );
+    socket->SetEventHandler( *this, ID_EDA_SOCKET_EVENT );
+    socket->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
 }
 
 
diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp
index b2fdeea212..f6e1dd4d10 100644
--- a/eeschema/eeschema.cpp
+++ b/eeschema/eeschema.cpp
@@ -83,7 +83,7 @@ static struct IFACE : public KIFACE_I
                 if( Kiface().IsSingle() )
                 {
                     // only run this under single_top, not under a project manager.
-                    CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER );
+                    frame->CreateServer( KICAD_SCH_PORT_SERVICE_NUMBER );
                 }
                 return frame;
             }
diff --git a/include/draw_frame.h b/include/draw_frame.h
index 68e3aa8a97..21dfa53ee4 100644
--- a/include/draw_frame.h
+++ b/include/draw_frame.h
@@ -32,6 +32,7 @@
 #include <gal/gal_display_options.h>
 #include <gal/color4d.h>
 #include <class_draw_panel_gal.h>
+#include "hotkeys_basic.h"
 
 class wxSingleInstanceChecker;
 class EDA_HOTKEY;
@@ -72,9 +73,13 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER
 
 protected:
 
+    wxSocketServer*                          m_socketServer;
+    std::vector<wxSocketBase*>               m_sockets;         ///< interprocess communication
+
     std::unique_ptr<wxSingleInstanceChecker> m_file_checker;    ///< prevents opening same file multiple times.
 
-    EDA_HOTKEY_CONFIG* m_hotkeysDescrList;
+    EDA_HOTKEY_CONFIG*                       m_hotkeysDescrList;
+
     int         m_LastGridSizeId;           // the command id offset (>= 0) of the last selected grid
                                             // 0 is for the grid corresponding to
                                             // a wxCommand ID = ID_POPUP_GRID_LEVEL_1000.
@@ -772,6 +777,7 @@ public:
     void CopyToClipboard( wxCommandEvent& event );
 
     /* interprocess communication */
+    void CreateServer( int service, bool local = true );
     void OnSockRequest( wxSocketEvent& evt );
     void OnSockRequestServer( wxSocketEvent& evt );
 
diff --git a/include/eda_dde.h b/include/eda_dde.h
index 21cf722414..3bf77db514 100644
--- a/include/eda_dde.h
+++ b/include/eda_dde.h
@@ -45,7 +45,6 @@
 #define MSG_TO_PCB                      KICAD_PCB_PORT_SERVICE_NUMBER
 #define MSG_TO_SCH                      KICAD_SCH_PORT_SERVICE_NUMBER
 
-wxSocketServer* CreateServer( wxWindow * window, int port, bool local = true );
 bool SendCommand( int port, const char* cmdline );
 
 #endif    // EDA_DDE_H_
diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp
index 9636803b2a..3d2b400680 100644
--- a/pcbnew/pcbnew.cpp
+++ b/pcbnew/pcbnew.cpp
@@ -106,50 +106,42 @@ static struct IFACE : public KIFACE_I
 
     wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
     {
-        wxWindow* frame = NULL;
-
         switch( aClassId )
         {
         case FRAME_PCB:
-            frame = dynamic_cast< wxWindow* >( new PCB_EDIT_FRAME( aKiway, aParent ) );
+        {
+            auto frame = new PCB_EDIT_FRAME( aKiway, aParent );
 
 #if defined( KICAD_SCRIPTING )
             // give the scripting helpers access to our frame
-            ScriptingSetPcbEditFrame( (PCB_EDIT_FRAME*) frame );
+            ScriptingSetPcbEditFrame( frame );
 #endif
 
             if( Kiface().IsSingle() )
             {
                 // only run this under single_top, not under a project manager.
-                CreateServer( frame, KICAD_PCB_PORT_SERVICE_NUMBER );
+                frame->CreateServer( KICAD_PCB_PORT_SERVICE_NUMBER );
             }
 
-            break;
+            return frame;
+        }
 
         case FRAME_PCB_MODULE_EDITOR:
-            frame = dynamic_cast< wxWindow* >( new FOOTPRINT_EDIT_FRAME( aKiway, aParent ) );
-            break;
+            return new FOOTPRINT_EDIT_FRAME( aKiway, aParent );
 
         case FRAME_PCB_MODULE_VIEWER:
         case FRAME_PCB_MODULE_VIEWER_MODAL:
-            frame = dynamic_cast< wxWindow* >( new FOOTPRINT_VIEWER_FRAME( aKiway, aParent,
-                                                                           FRAME_T( aClassId ) ) );
-            break;
+            return new FOOTPRINT_VIEWER_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
 
         case FRAME_PCB_FOOTPRINT_WIZARD_MODAL:
-            frame = dynamic_cast< wxWindow* >( new FOOTPRINT_WIZARD_FRAME( aKiway, aParent,
-                                                                           FRAME_T( aClassId ) ) );
-            break;
+            return new FOOTPRINT_WIZARD_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
 
         case FRAME_PCB_FOOTPRINT_PREVIEW:
-            frame = dynamic_cast< wxWindow* >( FOOTPRINT_PREVIEW_PANEL::New( aKiway, aParent ) );
-            break;
+            return dynamic_cast< wxWindow* >( FOOTPRINT_PREVIEW_PANEL::New( aKiway, aParent ) );
 
         default:
-            break;
+            return nullptr;
         }
-
-        return frame;
     }
 
     /**