added Server/CVocaluxeServer.cs
This commit is contained in:
1 parent
29212e4c81
commit
7f71853672
10 files changed
+199
-10
No files matched your search
@@ -42,3 +42,8 @@ Output/Songs
|
|||||||
/ClientServerLib/ClientServerLib/ClientServerLib.csproj.user
|
/ClientServerLib/ClientServerLib/ClientServerLib.csproj.user
|
||||||
/ClientServerLib/ClientServerLib/bin/Debug/ClientServerLib.dll
|
/ClientServerLib/ClientServerLib/bin/Debug/ClientServerLib.dll
|
||||||
/ClientServerLib/ClientTest/bin/Debug/ClientServerLib.dll
|
/ClientServerLib/ClientTest/bin/Debug/ClientServerLib.dll
|
||||||
|
/ClientServerLib/ClientServerLib/bin/ClientServerLib.dll
|
||||||
|
/ClientServerLib/ClientTest/bin/Debug/ClientTest.exe
|
||||||
|
/ClientServerLib/ClientTest/bin/Debug/ClientTest.vshost.exe
|
||||||
|
/ClientServerLib/ClientTest/bin/Release/ClientTest.vshost.exe
|
||||||
|
/ClientServerLib/ClientTest/bin/Release/ClientTest.vshost.exe.manifest
|
||||||
@@ -25,6 +25,8 @@ namespace ClientServerLib
|
|||||||
private List<SRequest> requests;
|
private List<SRequest> requests;
|
||||||
private List<SRequest> responses;
|
private List<SRequest> responses;
|
||||||
private OnConnectionChanged onConnectionChanged;
|
private OnConnectionChanged onConnectionChanged;
|
||||||
|
private OnSend onSend;
|
||||||
|
private OnReceived onReceived;
|
||||||
|
|
||||||
public bool Connected
|
public bool Connected
|
||||||
{
|
{
|
||||||
@@ -51,12 +53,17 @@ namespace ClientServerLib
|
|||||||
clientThread.Start();
|
clientThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect(string IP = "127.0.0.1", int Port = 3000, OnConnectionChanged OnConnectionChanged = null)
|
public void Connect(string IP = "127.0.0.1", int Port = 3000,
|
||||||
|
OnConnectionChanged OnConnectionChanged = null,
|
||||||
|
OnSend OnSend = null,
|
||||||
|
OnReceived OnReceived = null)
|
||||||
{
|
{
|
||||||
if (!doConnect)
|
if (!doConnect)
|
||||||
{
|
{
|
||||||
if (OnConnectionChanged != null)
|
onConnectionChanged = OnConnectionChanged;
|
||||||
onConnectionChanged = OnConnectionChanged;
|
onSend = OnSend;
|
||||||
|
onReceived = OnReceived;
|
||||||
|
|
||||||
ip = IP;
|
ip = IP;
|
||||||
port = Port;
|
port = Port;
|
||||||
doConnect = true;
|
doConnect = true;
|
||||||
@@ -114,7 +121,7 @@ namespace ClientServerLib
|
|||||||
connected = true;
|
connected = true;
|
||||||
RaiseOnConnectionChanged();
|
RaiseOnConnectionChanged();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
connected = false;
|
connected = false;
|
||||||
RaiseOnConnectionChanged();
|
RaiseOnConnectionChanged();
|
||||||
@@ -134,6 +141,7 @@ namespace ClientServerLib
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection.TcpClient.Close();
|
connection.TcpClient.Close();
|
||||||
|
connection = new CConnection(new TcpClient(), -1);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -184,7 +192,10 @@ namespace ClientServerLib
|
|||||||
|
|
||||||
byte[] serverParam = new byte[bytesRead];
|
byte[] serverParam = new byte[bytesRead];
|
||||||
Array.Copy(data, serverParam, bytesRead);
|
Array.Copy(data, serverParam, bytesRead);
|
||||||
|
RaiseOnReceived(serverParam);
|
||||||
|
|
||||||
byte[] clientResponse = connection.CreateClientKey(serverParam);
|
byte[] clientResponse = connection.CreateClientKey(serverParam);
|
||||||
|
RaiseOnSend(clientResponse);
|
||||||
clientStream.Write(clientResponse, 0, clientResponse.Length);
|
clientStream.Write(clientResponse, 0, clientResponse.Length);
|
||||||
clientStream.Flush();
|
clientStream.Flush();
|
||||||
}
|
}
|
||||||
@@ -206,7 +217,8 @@ namespace ClientServerLib
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
responses[0].Callback(responses[0].Response);
|
if (responses[0].Callback != null)
|
||||||
|
responses[0].Callback(responses[0].Response);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -227,6 +239,7 @@ namespace ClientServerLib
|
|||||||
|
|
||||||
NetworkStream clientStream = connection.TcpClient.GetStream();
|
NetworkStream clientStream = connection.TcpClient.GetStream();
|
||||||
|
|
||||||
|
RaiseOnSend(request.Command);
|
||||||
byte[] encrypted = connection.Encrypt(request.Command);
|
byte[] encrypted = connection.Encrypt(request.Command);
|
||||||
|
|
||||||
clientStream.Write(encrypted, 0, encrypted.Length);
|
clientStream.Write(encrypted, 0, encrypted.Length);
|
||||||
@@ -257,6 +270,7 @@ namespace ClientServerLib
|
|||||||
encrypted = new byte[bytesRead];
|
encrypted = new byte[bytesRead];
|
||||||
Array.Copy(data, encrypted, bytesRead);
|
Array.Copy(data, encrypted, bytesRead);
|
||||||
response.Response = connection.Decrypt(encrypted);
|
response.Response = connection.Decrypt(encrypted);
|
||||||
|
RaiseOnReceived(response.Response);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -272,5 +286,29 @@ namespace ClientServerLib
|
|||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RaiseOnSend(byte[] Message)
|
||||||
|
{
|
||||||
|
if (onSend == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
onSend(Message);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RaiseOnReceived(byte[] Message)
|
||||||
|
{
|
||||||
|
if (onReceived == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
onReceived(Message);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,10 @@ namespace ClientServerLib
|
|||||||
{
|
{
|
||||||
public delegate void ResponseCallback(byte[] Response);
|
public delegate void ResponseCallback(byte[] Response);
|
||||||
public delegate byte[] HandleRequest(int ConnectionID, byte[] Message);
|
public delegate byte[] HandleRequest(int ConnectionID, byte[] Message);
|
||||||
|
|
||||||
public delegate void OnConnectionChanged(bool Connected);
|
public delegate void OnConnectionChanged(bool Connected);
|
||||||
|
public delegate void OnSend(byte[] Message);
|
||||||
|
public delegate void OnReceived(byte[] Message);
|
||||||
|
|
||||||
public struct SRequest
|
public struct SRequest
|
||||||
{
|
{
|
||||||
|
|||||||
+37
@@ -41,6 +41,9 @@
|
|||||||
this.lbDateSending = new System.Windows.Forms.Label();
|
this.lbDateSending = new System.Windows.Forms.Label();
|
||||||
this.lbDataReceiving = new System.Windows.Forms.Label();
|
this.lbDataReceiving = new System.Windows.Forms.Label();
|
||||||
this.tbDataReceiving = new System.Windows.Forms.TextBox();
|
this.tbDataReceiving = new System.Windows.Forms.TextBox();
|
||||||
|
this.tbPassword = new System.Windows.Forms.TextBox();
|
||||||
|
this.lbPassword = new System.Windows.Forms.Label();
|
||||||
|
this.btLogin = new System.Windows.Forms.Button();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.panel1.SuspendLayout();
|
this.panel1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@@ -114,6 +117,9 @@
|
|||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
|
this.panel1.Controls.Add(this.btLogin);
|
||||||
|
this.panel1.Controls.Add(this.lbPassword);
|
||||||
|
this.panel1.Controls.Add(this.tbPassword);
|
||||||
this.panel1.Controls.Add(this.lbServerIP);
|
this.panel1.Controls.Add(this.lbServerIP);
|
||||||
this.panel1.Controls.Add(this.btConnect);
|
this.panel1.Controls.Add(this.btConnect);
|
||||||
this.panel1.Controls.Add(this.tbServerIP);
|
this.panel1.Controls.Add(this.tbServerIP);
|
||||||
@@ -162,6 +168,34 @@
|
|||||||
this.tbDataReceiving.Size = new System.Drawing.Size(804, 120);
|
this.tbDataReceiving.Size = new System.Drawing.Size(804, 120);
|
||||||
this.tbDataReceiving.TabIndex = 9;
|
this.tbDataReceiving.TabIndex = 9;
|
||||||
//
|
//
|
||||||
|
// tbPassword
|
||||||
|
//
|
||||||
|
this.tbPassword.Location = new System.Drawing.Point(85, 113);
|
||||||
|
this.tbPassword.Name = "tbPassword";
|
||||||
|
this.tbPassword.Size = new System.Drawing.Size(86, 20);
|
||||||
|
this.tbPassword.TabIndex = 6;
|
||||||
|
this.tbPassword.Text = "vocaluxe";
|
||||||
|
//
|
||||||
|
// lbPassword
|
||||||
|
//
|
||||||
|
this.lbPassword.AutoSize = true;
|
||||||
|
this.lbPassword.Location = new System.Drawing.Point(3, 116);
|
||||||
|
this.lbPassword.Name = "lbPassword";
|
||||||
|
this.lbPassword.Size = new System.Drawing.Size(56, 13);
|
||||||
|
this.lbPassword.TabIndex = 7;
|
||||||
|
this.lbPassword.Text = "Password:";
|
||||||
|
//
|
||||||
|
// btLogin
|
||||||
|
//
|
||||||
|
this.btLogin.Enabled = false;
|
||||||
|
this.btLogin.Location = new System.Drawing.Point(6, 139);
|
||||||
|
this.btLogin.Name = "btLogin";
|
||||||
|
this.btLogin.Size = new System.Drawing.Size(165, 23);
|
||||||
|
this.btLogin.TabIndex = 8;
|
||||||
|
this.btLogin.Text = "Login";
|
||||||
|
this.btLogin.UseVisualStyleBackColor = true;
|
||||||
|
this.btLogin.Click += new System.EventHandler(this.btLogin_Click);
|
||||||
|
//
|
||||||
// ClientTest
|
// ClientTest
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@@ -199,6 +233,9 @@
|
|||||||
private System.Windows.Forms.Label lbDateSending;
|
private System.Windows.Forms.Label lbDateSending;
|
||||||
private System.Windows.Forms.Label lbDataReceiving;
|
private System.Windows.Forms.Label lbDataReceiving;
|
||||||
private System.Windows.Forms.TextBox tbDataReceiving;
|
private System.Windows.Forms.TextBox tbDataReceiving;
|
||||||
|
private System.Windows.Forms.Button btLogin;
|
||||||
|
private System.Windows.Forms.Label lbPassword;
|
||||||
|
private System.Windows.Forms.TextBox tbPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +37,11 @@ namespace ClientTest
|
|||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btLogin_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void Connect()
|
private void Connect()
|
||||||
{
|
{
|
||||||
int port = 3000;
|
int port = 3000;
|
||||||
@@ -54,7 +59,7 @@ namespace ClientTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
lbConnectionStatusText.Text = "Connecting...";
|
lbConnectionStatusText.Text = "Connecting...";
|
||||||
client.Connect(tbServerIP.Text, port, OnConnectionChanged);
|
client.Connect(tbServerIP.Text, port, OnConnectionChanged, OnSend, OnReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Disconnect()
|
private void Disconnect()
|
||||||
@@ -65,12 +70,59 @@ namespace ClientTest
|
|||||||
private void OnConnectionChanged(bool Connected)
|
private void OnConnectionChanged(bool Connected)
|
||||||
{
|
{
|
||||||
if (Connected)
|
if (Connected)
|
||||||
lbConnectionStatusText.Text = "Connected";
|
{
|
||||||
|
this.Invoke((MethodInvoker)delegate
|
||||||
|
{
|
||||||
|
lbConnectionStatusText.Text = "Connected";
|
||||||
|
btConnect.Text = "Disconnect";
|
||||||
|
btLogin.Enabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
client.Disconnect();
|
this.Invoke((MethodInvoker)delegate
|
||||||
lbConnectionStatusText.Text = "Disconnected";
|
{
|
||||||
|
client.Disconnect();
|
||||||
|
lbConnectionStatusText.Text = "Disconnected";
|
||||||
|
btConnect.Text = "Connect";
|
||||||
|
btLogin.Text = "Login";
|
||||||
|
btLogin.Enabled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSend(byte[] Message)
|
||||||
|
{
|
||||||
|
if (Message == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string text = String.Empty;
|
||||||
|
foreach (byte b in Message)
|
||||||
|
{
|
||||||
|
text += b.ToString() + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Invoke((MethodInvoker)delegate
|
||||||
|
{
|
||||||
|
tbDataSending.Text = text;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReceived(byte[] Message)
|
||||||
|
{
|
||||||
|
if (Message == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string text = String.Empty;
|
||||||
|
foreach (byte b in Message)
|
||||||
|
{
|
||||||
|
text += b.ToString() + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Invoke((MethodInvoker)delegate
|
||||||
|
{
|
||||||
|
tbDataReceiving.Text = text;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -112,6 +112,10 @@ namespace Vocaluxe.Base
|
|||||||
public static EWebcamLib WebcamLib = EWebcamLib.OpenCV;
|
public static EWebcamLib WebcamLib = EWebcamLib.OpenCV;
|
||||||
public static SWebcamConfig WebcamConfig;
|
public static SWebcamConfig WebcamConfig;
|
||||||
|
|
||||||
|
// Server
|
||||||
|
public static EOffOn Server = EOffOn.TR_CONFIG_ON;
|
||||||
|
public static int ServerPort = 3000;
|
||||||
|
|
||||||
//Lists to save parameters and values
|
//Lists to save parameters and values
|
||||||
private static readonly List<string> _Params = new List<string>();
|
private static readonly List<string> _Params = new List<string>();
|
||||||
private static readonly List<string> _Values = new List<string>();
|
private static readonly List<string> _Values = new List<string>();
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using ClientServerLib;
|
||||||
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
|
namespace Vocaluxe.Base.Server
|
||||||
|
{
|
||||||
|
static class CVocaluxeServer
|
||||||
|
{
|
||||||
|
private static CServer _Server;
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
_Server = new CServer(RequestHandler, CConfig.ServerPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Start()
|
||||||
|
{
|
||||||
|
if (CConfig.Server == EOffOn.TR_CONFIG_ON)
|
||||||
|
_Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Close()
|
||||||
|
{
|
||||||
|
_Server.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] RequestHandler(int ConnectionID, byte[] Message)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-1
@@ -26,6 +26,7 @@ using System.Windows.Forms;
|
|||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using Vocaluxe.Base.Font;
|
using Vocaluxe.Base.Font;
|
||||||
|
using Vocaluxe.Base.Server;
|
||||||
|
|
||||||
namespace Vocaluxe
|
namespace Vocaluxe
|
||||||
{
|
{
|
||||||
@@ -183,6 +184,13 @@ namespace Vocaluxe
|
|||||||
|
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
|
|
||||||
|
// Init Server
|
||||||
|
CLog.StartBenchmark(0, "Init Server");
|
||||||
|
CVocaluxeServer.Init();
|
||||||
|
CLog.StopBenchmark(0, "Init Server");
|
||||||
|
|
||||||
|
Application.DoEvents();
|
||||||
|
|
||||||
// Init Input
|
// Init Input
|
||||||
CLog.StartBenchmark(0, "Init Input");
|
CLog.StartBenchmark(0, "Init Input");
|
||||||
CController.Init();
|
CController.Init();
|
||||||
@@ -210,6 +218,7 @@ namespace Vocaluxe
|
|||||||
|
|
||||||
// Start Main Loop
|
// Start Main Loop
|
||||||
_SplashScreen.Close();
|
_SplashScreen.Close();
|
||||||
|
CVocaluxeServer.Start();
|
||||||
|
|
||||||
CDraw.MainLoop();
|
CDraw.MainLoop();
|
||||||
}
|
}
|
||||||
@@ -219,7 +228,7 @@ namespace Vocaluxe
|
|||||||
// Unloading
|
// Unloading
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CLog.CloseAll();
|
CVocaluxeServer.Close();
|
||||||
CController.Close();
|
CController.Close();
|
||||||
CSound.RecordCloseAll();
|
CSound.RecordCloseAll();
|
||||||
CSound.CloseAllStreams();
|
CSound.CloseAllStreams();
|
||||||
@@ -227,6 +236,7 @@ namespace Vocaluxe
|
|||||||
CDraw.Unload();
|
CDraw.Unload();
|
||||||
CDataBase.CloseConnections();
|
CDataBase.CloseConnections();
|
||||||
CWebcam.Close();
|
CWebcam.Close();
|
||||||
|
CLog.CloseAll();
|
||||||
}
|
}
|
||||||
catch (Exception) {}
|
catch (Exception) {}
|
||||||
Environment.Exit(Environment.ExitCode);
|
Environment.Exit(Environment.ExitCode);
|
||||||
|
|||||||
@@ -152,6 +152,9 @@
|
|||||||
<HintPath>..\Output\AForge.Video.DirectShow.dll</HintPath>
|
<HintPath>..\Output\AForge.Video.DirectShow.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="ClientServerLib">
|
||||||
|
<HintPath>..\ClientServerLib\ClientServerLib\bin\ClientServerLib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Community.CsharpSqlite">
|
<Reference Include="Community.CsharpSqlite">
|
||||||
<HintPath>..\Output\Community.CsharpSqlite.dll</HintPath>
|
<HintPath>..\Output\Community.CsharpSqlite.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -197,6 +200,7 @@
|
|||||||
<Compile Include="Base\CWebcam.cs" />
|
<Compile Include="Base\CWebcam.cs" />
|
||||||
<Compile Include="Base\Font\CFonts.cs" />
|
<Compile Include="Base\Font\CFonts.cs" />
|
||||||
<Compile Include="Base\Font\CGlyph.cs" />
|
<Compile Include="Base\Font\CGlyph.cs" />
|
||||||
|
<Compile Include="Base\Server\CVocaluxeServer.cs" />
|
||||||
<Compile Include="CSplashScreen.cs">
|
<Compile Include="CSplashScreen.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
Reference in new issue
Block a user