Skip to content

Commit

Permalink
Added Extra try/catch blocks around socket connections
Browse files Browse the repository at this point in the history
  • Loading branch information
margro committed Jan 31, 2016
1 parent b60db40 commit dfde3d4
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 43 deletions.
1 change: 1 addition & 0 deletions TVServerKodi/Changelog.txt
@@ -1,5 +1,6 @@
1.12.0.131:
- Fixed: ListSchedules: don't add a parent schedule id when the schedule type = once
- Extra try/catch blocks around socket connections

1.12.0.130:
- Added: Support for the MediaPortal 2 version of the TV Server (needs SQLite support)
Expand Down
154 changes: 154 additions & 0 deletions TVServerKodi/Installer/MPEI_update_1_10.xml
Expand Up @@ -267,6 +267,160 @@



</ExtensionDescription>
<VersionDescription />
<DevelopmentStatus>Stable</DevelopmentStatus>
<OnlineLocation>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/TVServerXBMC-1.12.0.130.mpe1</OnlineLocation>
<ReleaseDate>2014-08-18T19:29:03</ReleaseDate>
<Tags>xbmc, kodi, tv server plugins</Tags>
<Location>..\bin\[Name]-[Version].mpe1</Location>
<Params>
<Items>
<SectionParam Name="Online Icon">
<Value />
<ValueType>String</ValueType>
<Description>The icon file of the package stored online (jpg,png,bmp)</Description>
</SectionParam>
<SectionParam Name="Configuration file">
<Value />
<ValueType>Template</ValueType>
<Description>The file used to configure the extension.
If it has .exe extension the will be executed.
If it has .dll extension it's started like MP plugin configuration.</Description>
</SectionParam>
<SectionParam Name="Online Screenshots">
<Value />
<ValueType>String</ValueType>
<Description>Online stored screenshot urls separated by ; </Description>
</SectionParam>
<SectionParam Name="Force to uninstall on update">
<Value>yes</Value>
<ValueType>Bool</ValueType>
<Description>Show dialog and force to uninstall previous version when updating an extension. Should only be disabled if you are using an NSIS/MSI installer.</Description>
</SectionParam>
</Items>
</Params>
</GeneralInfo>
<UniqueFileList>
<Items />
</UniqueFileList>
<ProjectSettings>
<FolderGroups />
</ProjectSettings>
<IsSkin>false</IsSkin>
</PackageClass>
<PackageClass>
<Version>2.0</Version>
<Groups>
<Items>
<GroupItem Name="TVServer_plugin">
<DisplayName>TVServer_plugin</DisplayName>
<DefaulChecked>true</DefaulChecked>
<Description>TVServer_plugin</Description>
<Files>
<Items />
</Files>
</GroupItem>
</Items>
</Groups>
<Sections>
<Items />
</Sections>
<Dependencies>
<Items>
<DependencyItem>
<Type>Installer</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>5</Minor>
<Build>0</Build>
<Revision>0</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>20</Minor>
<Build>999</Build>
<Revision>0</Revision>
</MaxVersion>
<WarnOnly>true</WarnOnly>
<Message>requires at least MPEI 1.5.x</Message>
<Name>MPEI</Name>
</DependencyItem>
<DependencyItem>
<Type>TvServer</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>9</Minor>
<Build>0</Build>
<Revision>0</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>20</Minor>
<Build>999</Build>
<Revision>0</Revision>
</MaxVersion>
<WarnOnly>true</WarnOnly>
<Message>requires MediaPortal TVServer version 1.5.* or above</Message>
<Name>MediaPortal TVServer</Name>
</DependencyItem>
<DependencyItem>
<Type>MediaPortal</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>1</Minor>
<Build>6</Build>
<Revision>27644</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>1</Minor>
<Build>6</Build>
<Revision>27644</Revision>
</MaxVersion>
<WarnOnly>false</WarnOnly>
<Message>requires MediaPortal version 1.1.6.27644 to 1.1.6.27644.</Message>
<Name>MediaPortal</Name>
</DependencyItem>
</Items>
</Dependencies>
<PluginDependencies>
<Items />
</PluginDependencies>
<GeneralInfo>
<Name>TVServerKodi</Name>
<Id>81b6b5e8-b4e0-4d1c-a2e2-cb2db54844f1</Id>
<Author>Marcel Groothuis, Prashant V</Author>
<HomePage>http://www.scintilla.utwente.nl/~marcelg/xbmc/tvserverxbmc.html</HomePage>
<ForumPage>http://forum.xbmc.org/forumdisplay.php?fid=171</ForumPage>
<UpdateUrl>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/MPEI_Update_1_10.xml</UpdateUrl>
<Version>
<Major>1</Major>
<Minor>12</Minor>
<Build>0</Build>
<Revision>131</Revision>
</Version>
<ExtensionDescription>With this plugin you can watch Live TV, recordings, EPG and schedules in XBMC (v12.0 or above) and Kodi





. The TVServerKodi plugin extends the MediaPortal TVServer with a dedicated RPC gateway to allow XBMC/Kodi to access and control the TVServer.











</ExtensionDescription>
<VersionDescription />
<DevelopmentStatus>Stable</DevelopmentStatus>
Expand Down
2 changes: 1 addition & 1 deletion TVServerKodi/Installer/TVServerKodi.xmp2
Expand Up @@ -201,7 +201,7 @@ Click Next to continue or Cancel to exit Setup.</Value>
<Major>1</Major>
<Minor>12</Minor>
<Build>0</Build>
<Revision>130</Revision>
<Revision>131</Revision>
</Version>
<ExtensionDescription>With this plugin you can watch Live TV, recordings, EPG and schedules in XBMC (v12.0 or above) and Kodi

Expand Down
66 changes: 38 additions & 28 deletions TVServerKodi/Listener.cs
Expand Up @@ -69,7 +69,7 @@ public bool StartListening()
}
catch (Exception e)
{
Log.Error("TVServerKodi: Unknown error : " + e.ToString());
Log.Error("TVServerKodi: Unexpected error in StartListening(): " + e.ToString());
Console.WriteLine(e.ToString());
}

Expand Down Expand Up @@ -119,40 +119,50 @@ public void Stop()

public void ListenForClients()
{
m_clients = new List<TcpClient>();
m_communicationThreads = new List<Thread>();
cmdMutex = new Mutex();

while (!stopme)
try
{
Console.WriteLine("Waiting for clients...");
Log.Debug("TVServerKodi: Waiting for clients...");
while (!this.tcpListener.Pending())
m_clients = new List<TcpClient>();
m_communicationThreads = new List<Thread>();
cmdMutex = new Mutex();

while (!stopme)
{
Thread.Sleep(30);
}
Console.WriteLine("Waiting for clients...");
Log.Debug("TVServerKodi: Waiting for clients...");
while (!this.tcpListener.Pending())
{
Thread.Sleep(30);
}

// blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();
// blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();

// Multithreaded version:
Console.WriteLine("New Connection! Starting handler thread for client." + client.Client.RemoteEndPoint.ToString());
Log.Debug("TVServerKodi: New Connection! Starting handler thread for client." + client.Client.RemoteEndPoint.ToString());
//___________________________
lock(this) {
m_clients.Add(client);
}
// Multithreaded version:
Console.WriteLine("New Connection! Starting handler thread for client." + client.Client.RemoteEndPoint.ToString());
Log.Debug("TVServerKodi: New Connection! Starting handler thread for client." + client.Client.RemoteEndPoint.ToString());
//___________________________
lock (this)
{
m_clients.Add(client);
}

ConnectionHandler handler = new ConnectionHandler(client, cmdMutex, m_clients.Count);
ThreadStart thdstHandler = new ThreadStart(handler.HandleConnection);
Thread communicationThread = new Thread(thdstHandler);
lock(this) {
m_communicationThreads.Add(communicationThread);
ConnectionHandler handler = new ConnectionHandler(client, cmdMutex, m_clients.Count);
ThreadStart thdstHandler = new ThreadStart(handler.HandleConnection);
Thread communicationThread = new Thread(thdstHandler);
lock (this)
{
m_communicationThreads.Add(communicationThread);
}
communicationThread.Start();
}
communicationThread.Start();
}

tcpListener.Stop();
tcpListener.Stop();
}
catch (Exception e)
{
Log.Error("TVServerKodi: Unexpected error in ListenForClients(): " + e.ToString());
Console.WriteLine(e.ToString());
}
}
}
}
44 changes: 30 additions & 14 deletions TVServerKodi/Plugin.cs
Expand Up @@ -130,29 +130,45 @@ public void Stop()

private bool StartListenThread()
{
Log.Info("TVServerKodi: Start listening on port " + m_serverPort);
Console.WriteLine("TVServerKodi: Start listening on port " + m_serverPort);
try
{
Log.Info("TVServerKodi: Start listening on port " + m_serverPort);
Console.WriteLine("TVServerKodi: Start listening on port " + m_serverPort);

// start a thread for the listener
// start a thread for the listener

m_listener = new Listener(m_serverPort);
m_listener.StartListening();
m_listener = new Listener(m_serverPort);
m_listener.StartListening();
}
catch
{
Log.Error("TVServerKodi: StartListenThread failed!");
Console.WriteLine("StartListenThread failed!");
}

return false;
return false;
}

private void StopListenThread()
{
if (m_listener != null)
{
if (connected)
TVServerConnection.CloseAll();
try
{
if (m_listener != null)
{
if (connected)
TVServerConnection.CloseAll();

Log.Info("TVServerKodi: Stop listening");
Log.Info("TVServerKodi: Stop listening");

m_listener.Stop();
m_listener = null;
}
m_listener.Stop();
m_listener = null;
}
}
catch
{
Log.Error("TVServerKodi: StopListenThread failed!");
Console.WriteLine("StopListenThread failed!");
}
}

/// <summary>
Expand Down

0 comments on commit dfde3d4

Please sign in to comment.