From: <br...@us...> - 2008-06-02 13:33:17
|
Revision: 199 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=199&view=rev Author: brus07 Date: 2008-06-02 06:33:19 -0700 (Mon, 02 Jun 2008) Log Message: ----------- Fixed bug with close form Modified Paths: -------------- ACMServer/trunk/MediatorSolution/Library/Connector/SocketClient.cs ACMServer/trunk/MediatorSolution/Library/Connector/SocketServer.cs ACMServer/trunk/MediatorSolution/Mediator/Form1.cs ACMServer/trunk/MediatorSolution/Mediator/Library/Plugins/SocketGate/SocketServerPlugin.cs ACMServer/trunk/TesterSolution/Library/Connector/SocketClient.cs ACMServer/trunk/TesterSolution/Library/Connector/SocketServer.cs ACMServer/trunk/TesterSolution/Tester/Form1.cs Modified: ACMServer/trunk/MediatorSolution/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/MediatorSolution/Library/Connector/SocketClient.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/MediatorSolution/Library/Connector/SocketClient.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -10,17 +10,25 @@ public delegate void DataArrivedDelegate(string s); public event DataArrivedDelegate onDataArrived; + string ip = "127.0.0.1"; + int port = 4120; + public SocketClient() { } public SocketClient(string IP) { - client = new EasyClient(new ServerInfo(IP, 4120, true)); + this.ip = IP; + client = new EasyClient(new ServerInfo(this.ip, this.port, true)); client.DataArrived += DataArrived; } public void Connect() { + if (client == null) + { + client = new EasyClient(new ServerInfo(this.ip, this.port, true)); + } if (client.IsConnected == false) client.ConnectToServerAsync(); } @@ -28,6 +36,8 @@ { if (client.IsConnected == true) client.DisconnectFromServer(); + client.Dispose(); + client = null; } public void Send(string message) { @@ -42,6 +52,8 @@ } public bool IsConnected() { + if (client == null) + return false; return client.IsConnected; } } Modified: ACMServer/trunk/MediatorSolution/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/MediatorSolution/Library/Connector/SocketServer.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/MediatorSolution/Library/Connector/SocketServer.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -5,8 +5,10 @@ { public class SocketServer { - EasyServer server = new EasyServer(4120,true); + int port = 4120; + EasyServer server; + public delegate void DataArrivedDelegate(string s); public event DataArrivedDelegate onDataArrived; @@ -14,16 +16,24 @@ public SocketServer() { + server = new EasyServer(port, true); server.DataArrived += new DataArrived2Server_EventHandler(DataArrived); } public void Start() { + if (server == null) + server = new EasyServer(port, true); server.StartListen(); } public void Stop() { - server.StopListen(); + if (server != null) + { + server.StopListen(); + server.Dispose(); + server = null; + } } private void DataArrived(object Data, SocketStream DataSender) Modified: ACMServer/trunk/MediatorSolution/Mediator/Form1.cs =================================================================== --- ACMServer/trunk/MediatorSolution/Mediator/Form1.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/MediatorSolution/Mediator/Form1.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -43,7 +43,7 @@ private void button3_Click(object sender, EventArgs e) { - // socket.Stop(); + Disconnnect(); } private void DataArrived(string message) @@ -52,9 +52,16 @@ //TODO: doOther } + private void Disconnnect() + { + AcmContester.Mediator.Library.Plugins.SocketGate.CreaterMediatorPlugin socketCreater = new AcmContester.Mediator.Library.Plugins.SocketGate.CreaterMediatorPlugin(); + SocketServerPlugin b2 = (SocketServerPlugin)socketCreater.GetInstance(); + b2.Stop(); + } + private void Form1_FormClosing(object sender, FormClosingEventArgs e) { - // socket.Stop(); + Disconnnect(); } private void button4_Click(object sender, EventArgs e) Modified: ACMServer/trunk/MediatorSolution/Mediator/Library/Plugins/SocketGate/SocketServerPlugin.cs =================================================================== --- ACMServer/trunk/MediatorSolution/Mediator/Library/Plugins/SocketGate/SocketServerPlugin.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/MediatorSolution/Mediator/Library/Plugins/SocketGate/SocketServerPlugin.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -40,7 +40,16 @@ internal int CountClients() { + if (server == null) + return 0; return server.CountClients(); } + + internal void Stop() + { + if (server != null) + server.Stop(); + server = null; + } } } Modified: ACMServer/trunk/TesterSolution/Library/Connector/SocketClient.cs =================================================================== --- ACMServer/trunk/TesterSolution/Library/Connector/SocketClient.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/TesterSolution/Library/Connector/SocketClient.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -10,17 +10,25 @@ public delegate void DataArrivedDelegate(string s); public event DataArrivedDelegate onDataArrived; + string ip = "127.0.0.1"; + int port = 4120; + public SocketClient() { } public SocketClient(string IP) { - client = new EasyClient(new ServerInfo(IP, 4120, true)); + this.ip = IP; + client = new EasyClient(new ServerInfo(this.ip, this.port, true)); client.DataArrived += DataArrived; } public void Connect() { + if (client == null) + { + client = new EasyClient(new ServerInfo(this.ip, this.port, true)); + } if (client.IsConnected == false) client.ConnectToServerAsync(); } @@ -28,6 +36,8 @@ { if (client.IsConnected == true) client.DisconnectFromServer(); + client.Dispose(); + client = null; } public void Send(string message) { @@ -42,6 +52,8 @@ } public bool IsConnected() { + if (client == null) + return false; return client.IsConnected; } } Modified: ACMServer/trunk/TesterSolution/Library/Connector/SocketServer.cs =================================================================== --- ACMServer/trunk/TesterSolution/Library/Connector/SocketServer.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/TesterSolution/Library/Connector/SocketServer.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -5,8 +5,10 @@ { public class SocketServer { - EasyServer server = new EasyServer(4120,true); + int port = 4120; + EasyServer server; + public delegate void DataArrivedDelegate(string s); public event DataArrivedDelegate onDataArrived; @@ -14,16 +16,24 @@ public SocketServer() { + server = new EasyServer(port, true); server.DataArrived += new DataArrived2Server_EventHandler(DataArrived); } public void Start() { + if (server == null) + server = new EasyServer(port, true); server.StartListen(); } public void Stop() { - server.StopListen(); + if (server != null) + { + server.StopListen(); + server.Dispose(); + server = null; + } } private void DataArrived(object Data, SocketStream DataSender) Modified: ACMServer/trunk/TesterSolution/Tester/Form1.cs =================================================================== --- ACMServer/trunk/TesterSolution/Tester/Form1.cs 2008-06-02 12:05:01 UTC (rev 198) +++ ACMServer/trunk/TesterSolution/Tester/Form1.cs 2008-06-02 13:33:19 UTC (rev 199) @@ -29,9 +29,19 @@ private void button2_Click(object sender, EventArgs e) { - socket.Disconnect(); + Disconnect(); } + private void Disconnect() + { + if (socket != null) + { + if (socket.IsConnected() == true) + socket.Disconnect(); + socket = null; + } + } + private void button3_Click(object sender, EventArgs e) { if (socket.IsConnected() == false) @@ -47,9 +57,7 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e) { - if (socket != null) - if (socket.IsConnected() == true) - socket.Disconnect(); + Disconnect(); } private void timer1_Tick(object sender, EventArgs e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |