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. |
From: <br...@us...> - 2008-07-09 09:43:35
|
Revision: 294 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=294&view=rev Author: brus07 Date: 2008-07-09 02:43:28 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Move protocol classes to special directory. 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/SocketProtocol/ ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs Removed Paths: ------------- ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-07-08 21:14:53 UTC (rev 293) +++ ACMServer/trunk/ACMServer/Library/Connector/Connector.csproj 2008-07-09 09:43:28 UTC (rev 294) @@ -38,13 +38,13 @@ <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="SocketProtocol\EasyProtocol.cs" /> + <Compile Include="SocketProtocol\IProtocol.cs" /> <Compile Include="SocketServer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="WebConnector.cs" /> Deleted: ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs 2008-07-08 21:14:53 UTC (rev 293) +++ ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -1,36 +0,0 @@ -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 - } -} Deleted: ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs 2008-07-08 21:14:53 UTC (rev 293) +++ ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -1,11 +0,0 @@ -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); - } -} Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-08 21:14:53 UTC (rev 293) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -1,5 +1,6 @@ using System; using JadBenAutho.EasySocket; +using AcmContester.Library.Connector.SocketProtocol; namespace AcmContester.Library.Connector { Property changes on: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol ___________________________________________________________________ Name: tsvn:logminsize + 5 Copied: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs (from rev 293, ACMServer/trunk/ACMServer/Library/Connector/EasyProtocol.cs) =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -0,0 +1,36 @@ +using System; +using JadBenAutho.EasySocket; + +namespace AcmContester.Library.Connector.SocketProtocol +{ + 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 + } +} Property changes on: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs ___________________________________________________________________ Name: svn:mergeinfo + Copied: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs (from rev 293, ACMServer/trunk/ACMServer/Library/Connector/IProtocol.cs) =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs (rev 0) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -0,0 +1,11 @@ +using JadBenAutho.EasySocket; + +namespace AcmContester.Library.Connector.SocketProtocol +{ + interface IProtocol + { + void DataArrived(object message, ISocket socket); + void Send(object message, EasyServer server); + void Send(object message, EasyClient client); + } +} Property changes on: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs ___________________________________________________________________ Name: svn:mergeinfo + Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-08 21:14:53 UTC (rev 293) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-09 09:43:28 UTC (rev 294) @@ -1,5 +1,6 @@ using System; using JadBenAutho.EasySocket; +using AcmContester.Library.Connector.SocketProtocol; namespace AcmContester.Library.Connector { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2008-07-09 09:53:44
|
Revision: 295 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=295&view=rev Author: brus07 Date: 2008-07-09 02:53:53 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Refactoring of Protocol classes. All data transferring in string type. Modified Paths: -------------- ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs Modified: ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs 2008-07-09 09:43:28 UTC (rev 294) +++ ACMServer/trunk/ACMServer/Library/Connector/ISocket.cs 2008-07-09 09:53:53 UTC (rev 295) @@ -2,6 +2,6 @@ { interface ISocket { - void OnDataArrived(object data); + void OnDataArrived(string message); } } Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-09 09:43:28 UTC (rev 294) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketClient.cs 2008-07-09 09:53:53 UTC (rev 295) @@ -59,11 +59,11 @@ #region ISocket Members - public void OnDataArrived(object data) + public void OnDataArrived(string message) { if (onDataArrived != null) { - onDataArrived(data.ToString()); + onDataArrived(message); } } Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/EasyProtocol.cs 2008-07-09 09:53:53 UTC (rev 295) @@ -5,27 +5,20 @@ { class EasyProtocol: IProtocol { - int clientIndex = 0; #region IProtocol Members - public void DataArrived(object message, ISocket socket) + public void DataArrived(string message, ISocket socket) { socket.OnDataArrived(message); } - public void Send(object message, EasyServer server) + public void Send(string message, EasyServer server, int targerClientIndex) { - if (server.CountClients > 0) - { - if (clientIndex >= server.CountClients) - clientIndex = 0; - server.SendData(message, clientIndex); - clientIndex++; - } + server.SendData(message, targerClientIndex); } - public void Send(object message, EasyClient client) + public void Send(string message, EasyClient client) { if (client.IsConnected == true) client.SendData(message); Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs 2008-07-09 09:43:28 UTC (rev 294) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketProtocol/IProtocol.cs 2008-07-09 09:53:53 UTC (rev 295) @@ -4,8 +4,8 @@ { interface IProtocol { - void DataArrived(object message, ISocket socket); - void Send(object message, EasyServer server); - void Send(object message, EasyClient client); + void DataArrived(string message, ISocket socket); + void Send(string message, EasyServer server, int targerClientIndex); + void Send(string message, EasyClient client); } } Modified: ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-09 09:43:28 UTC (rev 294) +++ ACMServer/trunk/ACMServer/Library/Connector/SocketServer.cs 2008-07-09 09:53:53 UTC (rev 295) @@ -41,9 +41,16 @@ protocol.DataArrived(Data.ToString(), this); } + int clientIndex = 0; public void Send(string message) { - protocol.Send(message, server); + if (server.CountClients > 0) + { + if (clientIndex >= server.CountClients) + clientIndex = 0; + protocol.Send(message, server, clientIndex); + clientIndex++; + } } public int CountClients() @@ -53,11 +60,11 @@ #region ISocket Members - public void OnDataArrived(object data) + public void OnDataArrived(string message) { if (onDataArrived != null) { - onDataArrived(data.ToString()); + onDataArrived(message); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |