diff --git a/.gitignore b/.gitignore index b2aefb8..35f75c3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,12 +13,12 @@ /GKSimpleChat/obj/ /GKSimpleChat/temp/ -/DHT/bin/ -/DHT/obj/ - /DHTSample/bin/ /DHTSample/obj/ +/TCPChatTest/bin/ +/TCPChatTest/obj/ + /temp/ testrun_git.mswin.cmd diff --git a/GKConnectivity.sln b/GKConnectivity.sln index 3131d7d..b6a6adc 100644 --- a/GKConnectivity.sln +++ b/GKConnectivity.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GKNetPNRP", "GKNetPNRP\GKNe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DHTSample", "DHTSample\DHTSample.csproj", "{E19B390E-BA4C-4333-A4C1-2C390B1C1930}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TCPChatTest", "TCPChatTest\TCPChatTest.csproj", "{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Debug|Any CPU.Build.0 = Debug|Any CPU {E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Release|Any CPU.ActiveCfg = Release|Any CPU {E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Release|Any CPU.Build.0 = Release|Any CPU + {F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TCPChatTest/DataReceiveEventArgs.cs b/TCPChatTest/DataReceiveEventArgs.cs new file mode 100644 index 0000000..d34d33e --- /dev/null +++ b/TCPChatTest/DataReceiveEventArgs.cs @@ -0,0 +1,27 @@ +using System; +using System.Net; + +namespace TCPChatTest +{ + public class DataReceiveEventArgs : EventArgs + { + private byte[] fData; + private IPEndPoint fPeer; + + public DataReceiveEventArgs(byte[] data, IPEndPoint peer) + { + fData = data; + fPeer = peer; + } + + public IPEndPoint Peer + { + get { return fPeer; } + } + + public byte[] Data + { + get { return fData; } + } + } +} \ No newline at end of file diff --git a/TCPChatTest/Form1.Designer.cs b/TCPChatTest/Form1.Designer.cs new file mode 100644 index 0000000..f7e5ef0 --- /dev/null +++ b/TCPChatTest/Form1.Designer.cs @@ -0,0 +1,170 @@ +namespace TCPChatTest +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.txtLocalPort = new System.Windows.Forms.TextBox(); + this.btnConnect = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.btnSend = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.txtRemotePort = new System.Windows.Forms.TextBox(); + this.txtLog = new System.Windows.Forms.TextBox(); + this.txtMsg = new System.Windows.Forms.TextBox(); + this.txtRemoteAddress = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(72, 17); + this.label1.TabIndex = 0; + this.label1.Text = "Local Port"; + // + // txtLocalPort + // + this.txtLocalPort.Location = new System.Drawing.Point(13, 32); + this.txtLocalPort.Name = "txtLocalPort"; + this.txtLocalPort.Size = new System.Drawing.Size(142, 22); + this.txtLocalPort.TabIndex = 1; + this.txtLocalPort.Text = "11000"; + // + // btnConnect + // + this.btnConnect.Location = new System.Drawing.Point(315, 30); + this.btnConnect.Name = "btnConnect"; + this.btnConnect.Size = new System.Drawing.Size(138, 24); + this.btnConnect.TabIndex = 2; + this.btnConnect.Text = "Connect"; + this.btnConnect.UseVisualStyleBackColor = true; + this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 74); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(113, 17); + this.label2.TabIndex = 0; + this.label2.Text = "Remote Address"; + // + // btnSend + // + this.btnSend.Location = new System.Drawing.Point(326, 96); + this.btnSend.Name = "btnSend"; + this.btnSend.Size = new System.Drawing.Size(138, 24); + this.btnSend.TabIndex = 2; + this.btnSend.Text = "Send"; + this.btnSend.UseVisualStyleBackColor = true; + this.btnSend.Click += new System.EventHandler(this.btnSend_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(166, 74); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(87, 17); + this.label3.TabIndex = 0; + this.label3.Text = "Remote Port"; + // + // txtRemotePort + // + this.txtRemotePort.Location = new System.Drawing.Point(167, 97); + this.txtRemotePort.Name = "txtRemotePort"; + this.txtRemotePort.Size = new System.Drawing.Size(142, 22); + this.txtRemotePort.TabIndex = 1; + this.txtRemotePort.Text = "8888"; + // + // txtLog + // + this.txtLog.Location = new System.Drawing.Point(24, 208); + this.txtLog.Multiline = true; + this.txtLog.Name = "txtLog"; + this.txtLog.Size = new System.Drawing.Size(761, 227); + this.txtLog.TabIndex = 3; + // + // txtMsg + // + this.txtMsg.Location = new System.Drawing.Point(20, 133); + this.txtMsg.Name = "txtMsg"; + this.txtMsg.Size = new System.Drawing.Size(288, 22); + this.txtMsg.TabIndex = 4; + this.txtMsg.Text = "test"; + // + // txtRemoteAddress + // + this.txtRemoteAddress.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.txtRemoteAddress.FormattingEnabled = true; + this.txtRemoteAddress.Items.AddRange(new object[] { + "127.0.0.1", + "195.162.27.155"}); + this.txtRemoteAddress.Location = new System.Drawing.Point(15, 94); + this.txtRemoteAddress.Name = "txtRemoteAddress"; + this.txtRemoteAddress.Size = new System.Drawing.Size(140, 24); + this.txtRemoteAddress.TabIndex = 5; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.txtRemoteAddress); + this.Controls.Add(this.txtMsg); + this.Controls.Add(this.txtLog); + this.Controls.Add(this.btnSend); + this.Controls.Add(this.txtRemotePort); + this.Controls.Add(this.label3); + this.Controls.Add(this.btnConnect); + this.Controls.Add(this.label2); + this.Controls.Add(this.txtLocalPort); + this.Controls.Add(this.label1); + this.Name = "Form1"; + this.Text = "Form1"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtLocalPort; + private System.Windows.Forms.Button btnConnect; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button btnSend; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtRemotePort; + private System.Windows.Forms.TextBox txtLog; + private System.Windows.Forms.TextBox txtMsg; + private System.Windows.Forms.ComboBox txtRemoteAddress; + } +} + diff --git a/TCPChatTest/Form1.cs b/TCPChatTest/Form1.cs new file mode 100644 index 0000000..8f0d375 --- /dev/null +++ b/TCPChatTest/Form1.cs @@ -0,0 +1,45 @@ +using System; +using System.Net; +using System.Text; +using System.Windows.Forms; + +namespace TCPChatTest +{ + public partial class Form1 : Form + { + private TCPDuplexClient fClient; + + public Form1() + { + InitializeComponent(); + } + + private void btnConnect_Click(object sender, EventArgs e) + { + fClient = new TCPDuplexClient(); + fClient.DataReceive += RaiseDataReceive; + fClient.Start(int.Parse(txtLocalPort.Text)); + + txtLocalPort.Enabled = false; + btnConnect.Enabled = false; + } + + private void btnSend_Click(object sender, EventArgs e) + { + var endPoint = new IPEndPoint(IPAddress.Parse(txtRemoteAddress.Text), int.Parse(txtRemotePort.Text)); + fClient.Send(endPoint, txtMsg.Text); + } + + private void Form1_FormClosed(object sender, FormClosedEventArgs e) + { + //fServer.Disconnect(); + } + + public void RaiseDataReceive(object sender, DataReceiveEventArgs e) + { + Invoke((MethodInvoker)delegate { + txtLog.Text += Encoding.UTF8.GetString(e.Data) + "\r\n"; + }); + } + } +} diff --git a/TCPChatTest/Form1.resx b/TCPChatTest/Form1.resx new file mode 100644 index 0000000..29dcb1b --- /dev/null +++ b/TCPChatTest/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TCPChatTest/Program.cs b/TCPChatTest/Program.cs new file mode 100644 index 0000000..4e7f994 --- /dev/null +++ b/TCPChatTest/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace TCPChatTest +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/TCPChatTest/Properties/AssemblyInfo.cs b/TCPChatTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0312c9c --- /dev/null +++ b/TCPChatTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TCPChatTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TCPChatTest")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f0d4d14c-0635-4965-9ec4-8cfe5265cd17")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TCPChatTest/Properties/Resources.Designer.cs b/TCPChatTest/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f0ce71c --- /dev/null +++ b/TCPChatTest/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TCPChatTest.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TCPChatTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/TCPChatTest/Properties/Resources.resx b/TCPChatTest/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/TCPChatTest/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TCPChatTest/Properties/Settings.Designer.cs b/TCPChatTest/Properties/Settings.Designer.cs new file mode 100644 index 0000000..eba3842 --- /dev/null +++ b/TCPChatTest/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TCPChatTest.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/TCPChatTest/Properties/Settings.settings b/TCPChatTest/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/TCPChatTest/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TCPChatTest/TCPChatTest.csproj b/TCPChatTest/TCPChatTest.csproj new file mode 100644 index 0000000..800c215 --- /dev/null +++ b/TCPChatTest/TCPChatTest.csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {F0D4D14C-0635-4965-9EC4-8CFE5265CD17} + WinExe + TCPChatTest + TCPChatTest + v3.5 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + Form + + + Form1.cs + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + \ No newline at end of file diff --git a/TCPChatTest/TCPConnection.cs b/TCPChatTest/TCPConnection.cs new file mode 100644 index 0000000..11c8c72 --- /dev/null +++ b/TCPChatTest/TCPConnection.cs @@ -0,0 +1,90 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace TCPChatTest +{ + public class TCPConnection + { + protected internal string fId; + + private byte[] fBuffer = new byte[65535]; + private TCPDuplexClient fDuplexClient; + private Encoding fEncoding = Encoding.UTF8; + private Socket fSocket; + + public TCPConnection(TCPDuplexClient client, Socket socket, bool receive = true) + { + fId = Guid.NewGuid().ToString(); + fDuplexClient = client; + fDuplexClient.AddConnection(this); + + fSocket = socket; + + // Start listening for incoming data. (If you want a multi- + // threaded service, you can start this method up in a separate + // thread.) + + if (!receive) return; + BeginReceive(); + } + + // Call this method to set this connection's socket up to receive data. + private void BeginReceive() + { + fSocket.BeginReceive(fBuffer, 0, fBuffer.Length, SocketFlags.None, + new AsyncCallback(OnBytesReceived), this); + } + + // This is the method that is called whenever the socket receives + // incoming bytes. + protected void OnBytesReceived(IAsyncResult result) + { + // End the data receiving that the socket has done and get + // the number of bytes read. + int nBytesRec = fSocket.EndReceive(result); + // If no bytes were received, the connection is closed (at + // least as far as we're concerned). + if (nBytesRec <= 0) { + fSocket.Close(); + return; + } + + // Convert the data we have to a string. + string strReceived = fEncoding.GetString(fBuffer, 0, nBytesRec); + + IPEndPoint endPoint = (IPEndPoint)fSocket.RemoteEndPoint; + //endPoint = IPEndPoint. + fDuplexClient.RaiseDataReceive(fEncoding.GetBytes(strReceived), new IPEndPoint(IPAddress.Any, 0)); + + // ...Now, do whatever works best with the string data. + // You could, for example, look at each character in the string + // one-at-a-time and check for characters like the "end of text" + // character ('\u0003') from a client indicating that they've finished + // sending the current message. It's totally up to you how you want + // the protocol to work. + + // Whenever you decide the connection should be closed, call + // sock.Close() and don't call sock.BeginReceive() again. But as long + // as you want to keep processing incoming data... + + // Set up again to get the next chunk of data. + fSocket.BeginReceive(fBuffer, 0, fBuffer.Length, SocketFlags.None, + new AsyncCallback(OnBytesReceived), this); + } + + public void Send(string msg) + { + fSocket.Send(Encoding.UTF8.GetBytes(msg)); + } + + public void Close() + { + fDuplexClient.RemoveConnection(fId); + + fSocket.Shutdown(SocketShutdown.Both); + fSocket.Close(); + } + } +} \ No newline at end of file diff --git a/TCPChatTest/TCPDuplexClient.cs b/TCPChatTest/TCPDuplexClient.cs new file mode 100644 index 0000000..87348dd --- /dev/null +++ b/TCPChatTest/TCPDuplexClient.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; + +namespace TCPChatTest +{ + public class TCPDuplexClient + { + private int fBacklog; + private List fConnections = new List(); + private IPAddress fLocalAddress = IPAddress.Any; + private int fLocalPort; + private Socket fSocket; + + public event EventHandler DataReceive; + + // This is the method that starts the server listening. + public void Start(int port = 8080) + { + fLocalPort = port; + // Create the new socket on which we'll be listening. + fSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + // Bind the socket to the address and port. + fSocket.Bind(new IPEndPoint(IPAddress.Any, port)); + // Start listening. + fSocket.Listen(fBacklog); + // Set up the callback to be notified when somebody requests + // a new connection. + fSocket.BeginAccept(OnConnectRequest, fSocket); + } + + public void Disconnect() + { + for (int i = 0; i < fConnections.Count; i++) { + fConnections[i].Close(); + } + fSocket.Shutdown(SocketShutdown.Both); + fSocket.Close(); + } + + protected internal void AddConnection(TCPConnection connection) + { + fConnections.Add(connection); + } + + protected internal void RemoveConnection(string id) + { + // получаем по id закрытое подключение + TCPConnection connection = fConnections.FirstOrDefault(c => c.fId == id); + // и удаляем его из списка подключений + if (connection != null) + fConnections.Remove(connection); + } + + // This is the method that is called when the socket recives a request + // for a new connection. + private void OnConnectRequest(IAsyncResult result) + { + // Get the socket (which should be this listener's socket) from + // the argument. + Socket sock = (Socket)result.AsyncState; + // Create a new client connection, using the primary socket to + // spawn a new socket. + TCPConnection newConn = new TCPConnection(this, sock.EndAccept(result)); + // Tell the listener socket to start listening again. + sock.BeginAccept(OnConnectRequest, sock); + } + + public TCPConnection CreateConnection(IPEndPoint point) + { + var extSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + extSocket.Connect(point); + return new TCPConnection(this, extSocket, false); + } + + public void Send(IPEndPoint point, string msg) + { + var newConn = CreateConnection(point); + newConn.Send(msg); + } + + public void RaiseDataReceive(byte[] data, IPEndPoint peer) + { + if (DataReceive != null) { + DataReceive(this, new DataReceiveEventArgs(data, peer)); + } + } + } +} \ No newline at end of file diff --git a/TCPChatTest/app.config b/TCPChatTest/app.config new file mode 100644 index 0000000..cf7e7ab --- /dev/null +++ b/TCPChatTest/app.config @@ -0,0 +1,3 @@ + + + diff --git a/clean.cmd b/clean.cmd index 443bcae..dcdf6d6 100644 --- a/clean.cmd +++ b/clean.cmd @@ -9,11 +9,11 @@ rmdir .\GKNetPNRP\obj /s /q rmdir .\GKSimpleChat\bin /s /q rmdir .\GKSimpleChat\obj /s /q -rmdir .\DHT\bin /s /q -rmdir .\DHT\obj /s /q - rmdir .\DHTSample\bin /s /q rmdir .\DHTSample\obj /s /q +rmdir .\TCPChatTest\bin /s /q +rmdir .\TCPChatTest\obj /s /q + del logFile del msbuild.log