[Csharp-classlib-cvs] demos/TCPServer/TCP Server AssemblyInfo.cs,NONE,1.1 Main.cs,NONE,1.1 TCP Serve
Status: Inactive
Brought to you by:
generalpd
From: Marcel K. <gen...@us...> - 2005-05-13 06:12:49
|
Update of /cvsroot/csharp-classlib/demos/TCPServer/TCP Server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28677/TCPServer/TCP Server Added Files: AssemblyInfo.cs Main.cs TCP Server.prjx Log Message: - added TCP server demo --- NEW FILE: Main.cs --- // C# ClassLib (Demos) // http://csharp-classlib.sourceforge.net // // // Copyright (C) 2005 Marcel Joachim Kloubert // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // using System; using System.Text; namespace CSharp_ClassLib.Demos.TCPServerClass { /*! \brief Main class * * Main class * * \author generalpd * * \version $Revision: 1.1 $ * * \date 2005-05-13 * * \bug none * * \todo none * * \remarks Last changed by: $Author: generalpd $ in revision $Revision: 1.1 $ on $Date: 2005/05/13 06:12:34 $ * * \note * $Log: Main.cs,v $ * Revision 1.1 2005/05/13 06:12:34 generalpd * - added TCP server demo * * */ public class MainClass { private CSharp_ClassLib.Net.TCPServer m_oTCPServer; /*! \fn MainClass () * \brief Class constructor * */ public MainClass () { return; } /*! \fn System.Int32 Main(System.String[] args) * \brief Entry point * * \param args Array of command line arguments * * \return Error code (0 => no error; 1 => Exception) * */ public static System.Int32 Main(System.String[] args) { return ( new CSharp_ClassLib.Demos.TCPServerClass.MainClass() ).Run( args ); } /*! \fn System.Int32 Run (System.String[] args) * \brief Internal, non-static method like Main() * * \param args Array of command line arguments * * \return Error code (0 => no error; 1 => Exception) * */ private System.Int32 Run (System.String[] args) { System.String strCommandLine = ""; System.Boolean boolLeaveApp = false; try { Console.WriteLine("Try to init and start TCP server on port 2309..."); this.m_oTCPServer = new CSharp_ClassLib.Net.TCPServer(); this.m_oTCPServer.MaxConnections = 10; this.m_oTCPServer.Port = 2309; this.m_oTCPServer.OnAccept += new CSharp_ClassLib.Net.TCPServer.AcceptHandler( this.m_oTCPServer_OnAccept ); this.m_oTCPServer.OnReceive += new CSharp_ClassLib.Net.TCPServer.ReceiveHandler( this.m_oTCPServer_OnReceive ); this.m_oTCPServer.OnError += new CSharp_ClassLib.Net.TCPServer.ErrorHandler( this.m_oTCPServer_OnError ); this.m_oTCPServer.OnDisconnect += new CSharp_ClassLib.Net.TCPServer.DisconnectHandler( this.m_oTCPServer_OnDisconnect ); this.m_oTCPServer.Start(); Console.WriteLine("... done!"); Console.WriteLine("\nTo leave the application, press 'q'."); while ( !boolLeaveApp ) { Console.Write("\n> "); strCommandLine = Console.ReadLine(); switch ( strCommandLine.ToLower().Trim() ) { case "q": // leave app boolLeaveApp = true; break; default: // unknown command Console.WriteLine("[Menu error!] UNKNOWN COMMAND!\n"); break; } } this.m_oTCPServer.Stop(); return 0; } catch (System.Exception e) { Console.WriteLine("[EXCEPTION!]: " + e.Message); return 1; } } /*! \fn void m_oTCPServer_OnAccept (System.Object sender, System.Net.Sockets.Socket socket) * \brief Event that is invoked if a client connected * * \param sender The TCP server instance * \param socket The socket that represents the connection between the TCP server and the client * */ private void m_oTCPServer_OnAccept (System.Object sender, System.Net.Sockets.Socket socket) { Console.WriteLine ("[m_oTCPServer_OnAccept event]: Connection established with: " + socket.RemoteEndPoint.ToString() + "\n" ); return; } /*! \fn void m_oTCPServer_OnReceive (System.Object sender, System.Net.Sockets.Socket socket, System.Byte[] buffer) * \brief Event that is invoked if data is available * * \param sender The TCP server instance * \param socket The socket from where the data comes * \param buffer Buffer with all data * */ private void m_oTCPServer_OnReceive (System.Object sender, System.Net.Sockets.Socket socket, System.Byte[] buffer) { System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding(); Console.WriteLine ("[m_oTCPServer_OnReceive event]: Data from " + socket.RemoteEndPoint.ToString() + ": " + ascii.GetString(buffer) + "\n" ); // send all data back like an echo socket.Send(buffer); return; } /*! \fn void m_oTCPServer_OnError (System.Object sender, System.Exception e) * \brief Event that is invoked if an exception occures * * \param sender The TCP server instance * \param e The exception * */ private void m_oTCPServer_OnError (System.Object sender, System.Exception e) { Console.WriteLine ("[m_oTCPServer_OnError event]: Exception: " + e.Message + "\n" ); return; } /*! \fn void m_oTCPServer_OnDisconnect (System.Object sender) * \brief Event that is invoked if a client connected * * \param sender The TCP server instance * */ private void m_oTCPServer_OnDisconnect (System.Object sender) { Console.WriteLine ("[m_oTCPServer_OnDisconnect event]: Connection closed with client.\n" ); return; } } } --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; // Information about this assembly is defined by the following // attributes. // // change them to the information which is associated with the assembly // you compile. [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // The assembly version has following format : // // Major.Minor.Build.Revision // // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): [assembly: AssemblyVersion("1.0.*")] // The following attributes specify the key for the sign of your assembly. See the // .NET Framework documentation for more information about signing. // This is not required, if you don't want signing let these attributes like they're. [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] --- NEW FILE: TCP Server.prjx --- <Project name="TCP Server" standardNamespace="TCP_Server" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#"> <Contents> <File name=".\Main.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> <File name=".\Classes" subtype="Directory" buildaction="Compile" dependson="" data="" /> <File name=".\Classes\clsTCPServer.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> </Contents> <References /> <DeploymentInformation target="" script="" strategy="File" /> <Configuration runwithwarnings="True" name="Debug"> <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="Exe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" /> <Execution commandlineparameters="" consolepause="True" /> <Output directory="..\bin\Debug" assembly="TCP Server" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> </Configuration> <Configurations active="Debug"> <Configuration runwithwarnings="True" name="Debug"> <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="True" optimize="False" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" target="Exe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" /> <Execution commandlineparameters="" consolepause="True" /> <Output directory="..\bin\Debug" assembly="TCP Server" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> </Configuration> <Configuration runwithwarnings="True" name="Release"> <CodeGeneration runtime="MsNet" compiler="Csc" compilerversion="" warninglevel="4" nowarn="" includedebuginformation="False" optimize="True" unsafecodeallowed="False" generateoverflowchecks="False" mainclass="" target="Exe" definesymbols="" generatexmldocumentation="False" win32Icon="" noconfig="False" nostdlib="False" /> <Execution commandlineparameters="" consolepause="True" /> <Output directory="..\bin\Release" assembly="TCP Server" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" /> </Configuration> </Configurations> </Project> |