|
From: <br...@us...> - 2008-07-08 21:14:49
|
Revision: 293
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=293&view=rev
Author: brus07
Date: 2008-07-08 14:14:53 -0700 (Tue, 08 Jul 2008)
Log Message:
-----------
Add feature for using real protocol in Socket module. (pattern strategy)
Modified Paths:
--------------
ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj
ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs
ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs
Added Paths:
-----------
ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs
ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs
ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs
Modified: ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-07-08 18:41:35 UTC (rev 292)
+++ ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-07-08 21:14:53 UTC (rev 293)
@@ -38,9 +38,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="EasyProtocol.cs" />
<Compile Include="Getter\FileGetter.cs" />
<Compile Include="Getter\IGetter.cs" />
<Compile Include="Getter\WebGetter.cs" />
+ <Compile Include="IProtocol.cs" />
+ <Compile Include="ISocket.cs" />
<Compile Include="SocketClient.cs" />
<Compile Include="SocketServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Added: ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs 2008-07-08 21:14:53 UTC (rev 293)
@@ -0,0 +1,36 @@
+using System;
+using JadBenAutho.EasySocket;
+
+namespace AcmContester.Library.Connector
+{
+ class EasyProtocol: IProtocol
+ {
+ int clientIndex = 0;
+
+ #region IProtocol Members
+
+ public void DataArrived(object message, ISocket socket)
+ {
+ socket.OnDataArrived(message);
+ }
+
+ public void Send(object message, EasyServer server)
+ {
+ if (server.CountClients > 0)
+ {
+ if (clientIndex >= server.CountClients)
+ clientIndex = 0;
+ server.SendData(message, clientIndex);
+ clientIndex++;
+ }
+ }
+
+ public void Send(object message, EasyClient client)
+ {
+ if (client.IsConnected == true)
+ client.SendData(message);
+ }
+
+ #endregion
+ }
+}
Added: ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs 2008-07-08 21:14:53 UTC (rev 293)
@@ -0,0 +1,11 @@
+using JadBenAutho.EasySocket;
+
+namespace AcmContester.Library.Connector
+{
+ interface IProtocol
+ {
+ void DataArrived(object message, ISocket socket);
+ void Send(object message, EasyServer server);
+ void Send(object message, EasyClient client);
+ }
+}
Added: ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs (rev 0)
+++ ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs 2008-07-08 21:14:53 UTC (rev 293)
@@ -0,0 +1,7 @@
+namespace AcmContester.Library.Connector
+{
+ interface ISocket
+ {
+ void OnDataArrived(object data);
+ }
+}
Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-08 18:41:35 UTC (rev 292)
+++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-08 21:14:53 UTC (rev 293)
@@ -3,9 +3,10 @@
namespace AcmContester.Library.Connector
{
- public class SocketClient
+ public class SocketClient: ISocket
{
EasyClient client;
+ IProtocol protocol = new EasyProtocol();
public delegate void DataArrivedDelegate(string s);
public event DataArrivedDelegate onDataArrived;
@@ -41,14 +42,12 @@
}
public void Send(string message)
{
- if (client.IsConnected == true)
- client.SendData(message);
+ protocol.Send(message, client);
}
- private void DataArrived(object message)
+ private void DataArrived(object Data)
{
- if (onDataArrived != null)
- onDataArrived(message.ToString());
+ protocol.DataArrived(Data.ToString(), this);
}
public bool IsConnected()
{
@@ -56,5 +55,17 @@
return false;
return client.IsConnected;
}
+
+ #region ISocket Members
+
+ public void OnDataArrived(object data)
+ {
+ if (onDataArrived != null)
+ {
+ onDataArrived(data.ToString());
+ }
+ }
+
+ #endregion
}
}
Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs
===================================================================
--- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-08 18:41:35 UTC (rev 292)
+++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-08 21:14:53 UTC (rev 293)
@@ -3,17 +3,16 @@
namespace AcmContester.Library.Connector
{
- public class SocketServer
+ public class SocketServer: ISocket
{
int port = 4120;
-
EasyServer server;
+ IProtocol protocol = new EasyProtocol();
+
public delegate void DataArrivedDelegate(string s);
public event DataArrivedDelegate onDataArrived;
- int clientIndex = 0;
-
public SocketServer()
{
server = new EasyServer(port, true);
@@ -38,26 +37,29 @@
private void DataArrived(object Data, SocketStream DataSender)
{
- if (onDataArrived != null)
- {
- onDataArrived(Data.ToString());
- }
+ protocol.DataArrived(Data.ToString(), this);
}
public void Send(string message)
{
- if (server.CountClients > 0)
- {
- if (clientIndex >= server.CountClients)
- clientIndex = 0;
- server.SendData(message, clientIndex);
- clientIndex++;
- }
+ protocol.Send(message, server);
}
public int CountClients()
{
return server.CountClients;
}
+
+ #region ISocket Members
+
+ public void OnDataArrived(object data)
+ {
+ if (onDataArrived != null)
+ {
+ onDataArrived(data.ToString());
+ }
+ }
+
+ #endregion
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|