mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 17:05:39 +02:00
v0.8.3 - hotfix for disconnections issues , further network code improvment
This commit is contained in:
@@ -4,6 +4,7 @@ using System;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
public class TCPController
|
public class TCPController
|
||||||
@@ -42,6 +43,7 @@ public class TCPController
|
|||||||
NetworkStream nsReadStream = null;
|
NetworkStream nsReadStream = null;
|
||||||
TcpClient tcpClient = null;
|
TcpClient tcpClient = null;
|
||||||
bool bTCPConnectionOnline = false;
|
bool bTCPConnectionOnline = false;
|
||||||
|
string strReceiveBuffer;
|
||||||
|
|
||||||
// Main loop - do until diconnect button is clicked
|
// Main loop - do until diconnect button is clicked
|
||||||
while (!bCloseConnection)
|
while (!bCloseConnection)
|
||||||
@@ -71,8 +73,8 @@ public class TCPController
|
|||||||
bTCPConnectionOnline = true;
|
bTCPConnectionOnline = true;
|
||||||
tcpClient = tcpServer.AcceptTcpClient(); //if a connection exists, the server will accept it
|
tcpClient = tcpServer.AcceptTcpClient(); //if a connection exists, the server will accept it
|
||||||
nsReadStream = tcpClient.GetStream(); //networkstream is used to send/receive messages
|
nsReadStream = tcpClient.GetStream(); //networkstream is used to send/receive messages
|
||||||
nsReadStream.ReadTimeout = 6000;
|
nsReadStream.ReadTimeout = 10000;
|
||||||
tcpClient.ReceiveTimeout = 6000;
|
tcpClient.ReceiveTimeout = 10000;
|
||||||
|
|
||||||
|
|
||||||
while (tcpClient.Connected && !bCloseConnection && bTCPConnectionOnline) //while the client is connected, we look for incoming messages
|
while (tcpClient.Connected && !bCloseConnection && bTCPConnectionOnline) //while the client is connected, we look for incoming messages
|
||||||
@@ -103,6 +105,16 @@ public class TCPController
|
|||||||
strReceivedData = CompleteMessage.ToString();
|
strReceivedData = CompleteMessage.ToString();
|
||||||
Console.WriteLine("Sender: {0} Payload: {1}", null, strReceivedData);
|
Console.WriteLine("Sender: {0} Payload: {1}", null, strReceivedData);
|
||||||
|
|
||||||
|
string pattern = @"(\<SOT\>)+?.*?(\<EOT\>)+?";
|
||||||
|
|
||||||
|
foreach (Match match in Regex.Matches(strReceivedData, pattern))
|
||||||
|
{
|
||||||
|
strReceiveBuffer = match.Value;
|
||||||
|
|
||||||
|
Console.WriteLine("Found '{0}' at position {1} end {2}",match.Value, match.Index,match.Length);
|
||||||
|
Console.WriteLine("Prepared {0}", strReceiveBuffer.Substring(5, match.Length-10));
|
||||||
|
|
||||||
|
strReceivedData = strReceiveBuffer.Substring(5, match.Length - 10);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (strReceivedData != "")
|
if (strReceivedData != "")
|
||||||
@@ -137,6 +149,19 @@ public class TCPController
|
|||||||
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP ERROR incorrect JSON > " + e.Message);
|
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP ERROR incorrect JSON > " + e.Message);
|
||||||
bTCPConnectionOnline = false;
|
bTCPConnectionOnline = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send empty byte to check if connection is still alive
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tcpClient.Client.Send(new byte[] { 0 }, 1, 0);
|
||||||
|
}
|
||||||
|
catch (SocketException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
PerunHelper.GUILogHistoryAdd(ref arrGUILogHistory, "#" + Globals.intInstanceId + " > TCP ERROR cannot send > " + e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.Threading.Thread.Sleep(500);
|
System.Threading.Thread.Sleep(500);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||||
<WebPage>Perun.htm</WebPage>
|
<WebPage>Perun.htm</WebPage>
|
||||||
<ApplicationRevision>0</ApplicationRevision>
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
<ApplicationVersion>0.8.2.%2a</ApplicationVersion>
|
<ApplicationVersion>0.8.3.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ using System.Runtime.InteropServices;
|
|||||||
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
|
// Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki
|
||||||
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
|
// przy użyciu symbolu „*”, tak jak pokazano poniżej:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.8.2.0")]
|
[assembly: AssemblyVersion("0.8.3.0")]
|
||||||
[assembly: AssemblyFileVersion("0.8.2.0")]
|
[assembly: AssemblyFileVersion("0.8.3.0")]
|
||||||
[assembly: NeutralResourcesLanguage("en")]
|
[assembly: NeutralResourcesLanguage("en")]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user