Skip to content

Commit

Permalink
Service and listener editing
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedikinci committed Sep 20, 2017
1 parent 88fbb6a commit f982054
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 26 deletions.
7 changes: 5 additions & 2 deletions FuzzyCore/Initialize/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public Init(string ProgramJsonPathArg,Action<Client> AcceptTask, Action<string,
public Init()
{
Message.Write("Basic Initializing",ConsoleMessage.MessageType.BACKPROCESS);
Message.Write("WCF Service is Running", ConsoleMessage.MessageType.BACKPROCESS);
ProgramJsonPath = "Program.json";
Host = new ServiceHost(typeof(Services.FuzzyService));
Host.Open();
Server = new FuzzyServer(new IPEndPoint(IPAddress.Any,111));
if (Host.State == CommunicationState.Opened)
{
Message.Write("WCF Service is Running", ConsoleMessage.MessageType.BACKPROCESS);
}
Server = new FuzzyServer(new IPEndPoint(IPAddress.Any,5959));
Server.startListen();
}
}
Expand Down
41 changes: 32 additions & 9 deletions FuzzyCore/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@ namespace FuzzyCore.Server
{
public class FuzzyServer
{
public static bool ReceiveData_Permission { get; set; } = true;
public static bool AcceptClient_Permission { get; set; } = true;
public static bool socketState { get { return SocketStatePrivate; } }
private static bool SocketStatePrivate = false;
private EndPoint localEP;
//
//BOOL
//
public static bool ReceiveData_Permission { get; set; } = true; //Data receiving control
public static bool AcceptClient_Permission { get; set; } = true; //Client accepting control
public static bool socketState { get { return SocketStatePrivate; } } //Socket Open/Close control get property
private static bool SocketStatePrivate = false; //Socket Open/Close Control

//
//BYTE
//
private byte[] _buff = new byte[1024];
private byte[] copyBuff;
private ConsoleMessage Message = new ConsoleMessage();

//
//LISTENER VARS
//
private Socket ServerSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
public static Dictionary<int, Client> SocketList = new Dictionary<int, Client>();
private ConsoleMessage Message = new ConsoleMessage();
public static string IPAndPort;
private EndPoint localEP;
Socket CurrentSocket;

//
//THREADS AND METHODS
//
private Thread DestroyThread = new Thread(new ThreadStart(() => {
while (true)
{
Expand All @@ -30,20 +47,26 @@ public class FuzzyServer
}));
public Action<string,Client> ReceiverTask;
public Action<Client> AcceptTask;
public static string IPAndPort;

//For Receive Catch Block
Socket CurrentSocket;
//
//CONSTRUCTOR
//
public FuzzyServer(EndPoint glEP)
{
this.localEP = glEP;
IPAndPort = localEP.ToString();
}

//
//STARTER METHOD
//
public void startListen()
{
try
{
//
//PERMISSION TRUE/FALSE CONTROL
//
if (!AcceptClient_Permission)
{
throw new Exception("Accept Client Permission Is False");
Expand Down
31 changes: 20 additions & 11 deletions FuzzyCore/Services/FuzzyService.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using FuzzyCore.Server;

namespace FuzzyCore.Services
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServerStatusService" in both code and config file together.
public class FuzzyService : IFuzzyService
{
public int GetClientCount()
{
return Server.FuzzyServer.SocketList.Count();
return FuzzyServer.SocketList.Count();
}

public string GetLastCommand()
Expand All @@ -22,7 +19,7 @@ public string GetLastCommand()

public string GetListeningIPAndPort()
{
return Server.FuzzyServer.IPAndPort;
return FuzzyServer.IPAndPort;
}

public string GetSelectedDatabase()
Expand All @@ -32,17 +29,29 @@ public string GetSelectedDatabase()

public bool GetServerStatus()
{
return Server.FuzzyServer.socketState;
return FuzzyServer.socketState;
}

public bool WorkingAcceptTask()
public bool AcceptTaskStatus()
{
return Server.FuzzyServer.AcceptClient_Permission;
return FuzzyServer.AcceptClient_Permission;
}

public bool WorkingReceiveTask()
public bool ReceiveTaskStatus()
{
return Server.FuzzyServer.ReceiveData_Permission;
return FuzzyServer.ReceiveData_Permission;
}

public bool SetAcceptTask(bool TaskStatus)
{
FuzzyServer.AcceptClient_Permission = TaskStatus;
return FuzzyServer.AcceptClient_Permission;
}

public bool SetReceiveTask(bool TaskStatus)
{
FuzzyServer.ReceiveData_Permission = TaskStatus;
return FuzzyServer.ReceiveData_Permission;
}
}
}
12 changes: 8 additions & 4 deletions FuzzyCore/Services/IFuzzyService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using FuzzyCore.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
Expand All @@ -7,7 +8,6 @@

namespace FuzzyCore.Services
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IServerStatusService" in both code and config file together.
[ServiceContract]
public interface IFuzzyService
{
Expand All @@ -22,8 +22,12 @@ public interface IFuzzyService
[OperationContract]
string GetLastCommand();
[OperationContract]
bool WorkingAcceptTask();
bool AcceptTaskStatus();
[OperationContract]
bool WorkingReceiveTask();
bool ReceiveTaskStatus();
[OperationContract]
bool SetAcceptTask(bool TaskStatus);
[OperationContract]
bool SetReceiveTask(bool TaskStatus);
}
}
Binary file modified FuzzyCore/bin/Debug/FuzzyCore.dll
Binary file not shown.
Binary file modified FuzzyCore/bin/Debug/FuzzyCore.pdb
Binary file not shown.
Binary file modified FuzzyCore/obj/Debug/FuzzyCore.dll
Binary file not shown.
Binary file modified FuzzyCore/obj/Debug/FuzzyCore.pdb
Binary file not shown.

0 comments on commit f982054

Please sign in to comment.