├── DLL └── EIPNET.dll ├── EipNet.sln ├── EipNetClient ├── App.config ├── EipNetClient.csproj ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── EipNetServer ├── App.config ├── EipNetServer.csproj ├── Program.cs └── Properties │ └── AssemblyInfo.cs └── README.md /DLL/EIPNET.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontran2016/EipNet/7bf3e856960de7088e6d62408084e8309c0f7acf/DLL/EIPNET.dll -------------------------------------------------------------------------------- /EipNet.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EipNetServer", "EipNetServer\EipNetServer.csproj", "{13E8EA18-34DE-4529-82DC-CBDAA8A60BAC}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EipNetClient", "EipNetClient\EipNetClient.csproj", "{64E19989-C6D8-473A-A22A-80C3B96A3DF0}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {13E8EA18-34DE-4529-82DC-CBDAA8A60BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {13E8EA18-34DE-4529-82DC-CBDAA8A60BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {13E8EA18-34DE-4529-82DC-CBDAA8A60BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {13E8EA18-34DE-4529-82DC-CBDAA8A60BAC}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {64E19989-C6D8-473A-A22A-80C3B96A3DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {64E19989-C6D8-473A-A22A-80C3B96A3DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {64E19989-C6D8-473A-A22A-80C3B96A3DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {64E19989-C6D8-473A-A22A-80C3B96A3DF0}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /EipNetClient/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /EipNetClient/EipNetClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {64E19989-C6D8-473A-A22A-80C3B96A3DF0} 8 | WinExe 9 | Properties 10 | EipNetClient 11 | EipNetClient 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\DLL\EIPNET.dll 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Form 53 | 54 | 55 | Form1.cs 56 | 57 | 58 | 59 | 60 | Form1.cs 61 | 62 | 63 | ResXFileCodeGenerator 64 | Resources.Designer.cs 65 | Designer 66 | 67 | 68 | True 69 | Resources.resx 70 | 71 | 72 | SettingsSingleFileGenerator 73 | Settings.Designer.cs 74 | 75 | 76 | True 77 | Settings.settings 78 | True 79 | 80 | 81 | 82 | 83 | 84 | 85 | 92 | -------------------------------------------------------------------------------- /EipNetClient/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace EipNetClient 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.txtServer = new System.Windows.Forms.TextBox(); 34 | this.txtPort = new System.Windows.Forms.TextBox(); 35 | this.btnConnect = new System.Windows.Forms.Button(); 36 | this.btnDisConnect = new System.Windows.Forms.Button(); 37 | this.btnSend = new System.Windows.Forms.Button(); 38 | this.label3 = new System.Windows.Forms.Label(); 39 | this.txtMsg = new System.Windows.Forms.TextBox(); 40 | this.label4 = new System.Windows.Forms.Label(); 41 | this.txtReceive = new System.Windows.Forms.TextBox(); 42 | this.SuspendLayout(); 43 | // 44 | // label1 45 | // 46 | this.label1.AutoSize = true; 47 | this.label1.Location = new System.Drawing.Point(60, 29); 48 | this.label1.Name = "label1"; 49 | this.label1.Size = new System.Drawing.Size(38, 13); 50 | this.label1.TabIndex = 0; 51 | this.label1.Text = "Server"; 52 | // 53 | // label2 54 | // 55 | this.label2.AutoSize = true; 56 | this.label2.Location = new System.Drawing.Point(235, 29); 57 | this.label2.Name = "label2"; 58 | this.label2.Size = new System.Drawing.Size(26, 13); 59 | this.label2.TabIndex = 1; 60 | this.label2.Text = "Port"; 61 | // 62 | // txtServer 63 | // 64 | this.txtServer.Location = new System.Drawing.Point(108, 26); 65 | this.txtServer.Name = "txtServer"; 66 | this.txtServer.Size = new System.Drawing.Size(100, 20); 67 | this.txtServer.TabIndex = 2; 68 | // 69 | // txtPort 70 | // 71 | this.txtPort.Location = new System.Drawing.Point(271, 26); 72 | this.txtPort.Name = "txtPort"; 73 | this.txtPort.Size = new System.Drawing.Size(47, 20); 74 | this.txtPort.TabIndex = 3; 75 | // 76 | // btnConnect 77 | // 78 | this.btnConnect.Location = new System.Drawing.Point(108, 184); 79 | this.btnConnect.Name = "btnConnect"; 80 | this.btnConnect.Size = new System.Drawing.Size(75, 23); 81 | this.btnConnect.TabIndex = 4; 82 | this.btnConnect.Text = "Connect"; 83 | this.btnConnect.UseVisualStyleBackColor = true; 84 | this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); 85 | // 86 | // btnDisConnect 87 | // 88 | this.btnDisConnect.Location = new System.Drawing.Point(189, 184); 89 | this.btnDisConnect.Name = "btnDisConnect"; 90 | this.btnDisConnect.Size = new System.Drawing.Size(75, 23); 91 | this.btnDisConnect.TabIndex = 5; 92 | this.btnDisConnect.Text = "DisConnect"; 93 | this.btnDisConnect.UseVisualStyleBackColor = true; 94 | this.btnDisConnect.Click += new System.EventHandler(this.btnDisConnect_Click); 95 | // 96 | // btnSend 97 | // 98 | this.btnSend.Location = new System.Drawing.Point(270, 184); 99 | this.btnSend.Name = "btnSend"; 100 | this.btnSend.Size = new System.Drawing.Size(75, 23); 101 | this.btnSend.TabIndex = 6; 102 | this.btnSend.Text = "Send"; 103 | this.btnSend.UseVisualStyleBackColor = true; 104 | this.btnSend.Click += new System.EventHandler(this.btnSend_Click); 105 | // 106 | // label3 107 | // 108 | this.label3.AutoSize = true; 109 | this.label3.Location = new System.Drawing.Point(48, 58); 110 | this.label3.Name = "label3"; 111 | this.label3.Size = new System.Drawing.Size(50, 13); 112 | this.label3.TabIndex = 7; 113 | this.label3.Text = "Message"; 114 | // 115 | // txtMsg 116 | // 117 | this.txtMsg.Location = new System.Drawing.Point(108, 52); 118 | this.txtMsg.Multiline = true; 119 | this.txtMsg.Name = "txtMsg"; 120 | this.txtMsg.Size = new System.Drawing.Size(210, 51); 121 | this.txtMsg.TabIndex = 8; 122 | // 123 | // label4 124 | // 125 | this.label4.AutoSize = true; 126 | this.label4.Location = new System.Drawing.Point(51, 112); 127 | this.label4.Name = "label4"; 128 | this.label4.Size = new System.Drawing.Size(47, 13); 129 | this.label4.TabIndex = 9; 130 | this.label4.Text = "Receive"; 131 | // 132 | // txtReceive 133 | // 134 | this.txtReceive.Location = new System.Drawing.Point(108, 109); 135 | this.txtReceive.Multiline = true; 136 | this.txtReceive.Name = "txtReceive"; 137 | this.txtReceive.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 138 | this.txtReceive.Size = new System.Drawing.Size(210, 51); 139 | this.txtReceive.TabIndex = 8; 140 | // 141 | // Form1 142 | // 143 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 144 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 145 | this.ClientSize = new System.Drawing.Size(422, 246); 146 | this.Controls.Add(this.label4); 147 | this.Controls.Add(this.txtReceive); 148 | this.Controls.Add(this.txtMsg); 149 | this.Controls.Add(this.label3); 150 | this.Controls.Add(this.btnSend); 151 | this.Controls.Add(this.btnDisConnect); 152 | this.Controls.Add(this.btnConnect); 153 | this.Controls.Add(this.txtPort); 154 | this.Controls.Add(this.txtServer); 155 | this.Controls.Add(this.label2); 156 | this.Controls.Add(this.label1); 157 | this.Name = "Form1"; 158 | this.Text = "Form1"; 159 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); 160 | this.Load += new System.EventHandler(this.Form1_Load); 161 | this.ResumeLayout(false); 162 | this.PerformLayout(); 163 | 164 | } 165 | 166 | #endregion 167 | 168 | private System.Windows.Forms.Label label1; 169 | private System.Windows.Forms.Label label2; 170 | private System.Windows.Forms.TextBox txtServer; 171 | private System.Windows.Forms.TextBox txtPort; 172 | private System.Windows.Forms.Button btnConnect; 173 | private System.Windows.Forms.Button btnDisConnect; 174 | private System.Windows.Forms.Button btnSend; 175 | private System.Windows.Forms.Label label3; 176 | private System.Windows.Forms.TextBox txtMsg; 177 | private System.Windows.Forms.Label label4; 178 | private System.Windows.Forms.TextBox txtReceive; 179 | } 180 | } 181 | 182 | -------------------------------------------------------------------------------- /EipNetClient/Form1.cs: -------------------------------------------------------------------------------- 1 | using EIPNET.EIP; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Net; 9 | using System.Net.Sockets; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | using System.Windows.Forms; 13 | 14 | namespace EipNetClient 15 | { 16 | public partial class Form1 : Form 17 | { 18 | private static string _server = "192.168.1.64";//"192.168.1.117" 19 | private static int _port = 44818; 20 | private static SessionInfo _si; 21 | public Form1() 22 | { 23 | InitializeComponent(); 24 | 25 | btnConnect.Enabled = true; 26 | btnDisConnect.Enabled = false; 27 | btnSend.Enabled = false; 28 | } 29 | private void Form1_Load(object sender, EventArgs e) 30 | { 31 | txtServer.Text = _server; 32 | txtPort.Text = ""+_port; 33 | } 34 | 35 | private void Form1_FormClosing(object sender, FormClosingEventArgs e) 36 | { 37 | if (_si!=null && _si.Connected) 38 | { 39 | SendData("Exit", EncapsCommand.UnRegisterSession); 40 | SessionManager.UnRegister(_si); 41 | } 42 | } 43 | private static EncapsReply SendData(string data, EncapsCommand cmd= EncapsCommand.NOP) 44 | { 45 | byte[] bytes = Encoding.Default.GetBytes(data); 46 | EncapsPacket request; 47 | switch (cmd) 48 | { 49 | case EncapsCommand.UnRegisterSession: 50 | request = EncapsPacketFactory.CreateUnRegisterSession(_si.SessionHandle, _si.SenderContext); 51 | break; 52 | default: 53 | request = EncapsPacketFactory.CreateNOP(bytes); 54 | break; 55 | } 56 | //var request = new EncapsPacket(); 57 | //request.EncapsData = bytes; 58 | //request.Length = (ushort)data.Length; 59 | //request.Command = (ushort)cmd; 60 | var msg = request.Pack(); 61 | var ar = _si.SendData_WaitReply(msg); 62 | var reply=new EncapsReply(); 63 | int tmp; 64 | if(ar!=null) 65 | reply.Expand(ar,0,out tmp); 66 | return reply; 67 | } 68 | private static string GetData(byte[] bytes) 69 | { 70 | var txt = Encoding.Default.GetString(bytes, 0, bytes.Length); 71 | return txt; 72 | } 73 | private void ChangeEnableButton() 74 | { 75 | btnConnect.Enabled = !btnConnect.Enabled; 76 | btnDisConnect.Enabled = !btnDisConnect.Enabled; 77 | btnSend.Enabled = !btnSend.Enabled; 78 | } 79 | 80 | private void btnConnect_Click(object sender, EventArgs e) 81 | { 82 | try 83 | { 84 | var hostName = Dns.GetHostName(); 85 | //IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName); 86 | //IPAddress ipAddress = ipHostInfo.AddressList.Single(x => x.AddressFamily == AddressFamily.InterNetwork); 87 | 88 | var context = Encoding.Default.GetBytes(hostName); 89 | _si = SessionManager.CreateAndRegister(txtServer.Text, int.Parse(txtPort.Text),context); 90 | if(!_si.Connected) 91 | throw new Exception(_si.LastSessionErrorString); 92 | ChangeEnableButton(); 93 | } 94 | catch (Exception ex) 95 | { 96 | MessageBox.Show(ex.Message); 97 | } 98 | } 99 | 100 | private void btnDisConnect_Click(object sender, EventArgs e) 101 | { 102 | try 103 | { 104 | if (_si.Connected) 105 | { 106 | var reply = SendData("Exit", EncapsCommand.UnRegisterSession); 107 | if (reply.Length > 0) 108 | SessionManager.UnRegister(_si); 109 | } 110 | ChangeEnableButton(); 111 | } 112 | catch (Exception ex) 113 | { 114 | MessageBox.Show(ex.Message); 115 | } 116 | } 117 | 118 | private void btnSend_Click(object sender, EventArgs e) 119 | { 120 | try 121 | { 122 | if (_si.Connected) 123 | { 124 | var reply = SendData(txtMsg.Text); 125 | if (reply.Length > 0) 126 | { 127 | var st = GetData(reply.EncapsData); 128 | if (txtReceive.Lines.Length == 0) 129 | txtReceive.Text = st; 130 | else 131 | txtReceive.AppendText("\r\n" + st); 132 | } 133 | else 134 | { 135 | ChangeEnableButton(); 136 | throw new Exception("Server not reply"); 137 | } 138 | } 139 | } 140 | catch (Exception ex) 141 | { 142 | MessageBox.Show(ex.Message); 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /EipNetClient/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /EipNetClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace EipNetClient 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /EipNetClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EipNetClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EipNetClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("64e19989-c6d8-473a-a22a-80c3b96a3df0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /EipNetClient/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace EipNetClient.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EipNetClient.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /EipNetClient/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /EipNetClient/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace EipNetClient.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /EipNetClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EipNetServer/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /EipNetServer/EipNetServer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {13E8EA18-34DE-4529-82DC-CBDAA8A60BAC} 8 | Exe 9 | Properties 10 | EipNetServer 11 | EipNetServer 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\DLL\EIPNET.dll 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 62 | -------------------------------------------------------------------------------- /EipNetServer/Program.cs: -------------------------------------------------------------------------------- 1 | using EIPNET.EIP; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Sockets; 7 | using System.Runtime.InteropServices; 8 | using System.Security.Cryptography.X509Certificates; 9 | using System.Text; 10 | using System.Threading; 11 | using System.Threading.Tasks; 12 | 13 | namespace EipNetServer 14 | { 15 | class Program 16 | { 17 | static void Main(string[] args) 18 | { 19 | StartListening(); 20 | } 21 | 22 | //private static string _server = "192.168.1.64";//"192.168.1.117"; 23 | private static int _port = 44818; 24 | private static bool _stop = false; 25 | private const int _bufferSize = 1024; 26 | public static void StartListening() 27 | { 28 | IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); 29 | IPAddress ipAddress = ipHostInfo.AddressList.First(x => x.AddressFamily == AddressFamily.InterNetwork); 30 | string _server = ipAddress.ToString(); 31 | IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(_server), _port); 32 | // Create a TCP/IP socket. 33 | Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp); 34 | 35 | // Bind the socket to the local endpoint and listen for incoming connections. 36 | try 37 | { 38 | listener.Bind(localEndPoint); 39 | listener.Listen(10); 40 | Console.WriteLine("Server started"); 41 | Console.WriteLine("Server IP: {0}",_server); 42 | var tListener = new Thread(() => 43 | { 44 | while (!_stop) 45 | { 46 | Console.WriteLine("Waiting for a new connection..."); 47 | Socket handler = listener.Accept(); 48 | Console.WriteLine("A client connected: "+ ((System.Net.IPEndPoint)handler.RemoteEndPoint).Address); 49 | 50 | var tReceive=new Thread(new ParameterizedThreadStart(BeginReceiveData)); 51 | tReceive.Start(handler); 52 | } 53 | }); 54 | tListener.Start(); 55 | 56 | //Console.WriteLine("Press exit"); 57 | //Console.ReadLine(); 58 | //_stop = true; 59 | //listener.Shutdown( SocketShutdown.Both); 60 | //listener.Close(); 61 | //tListener.Join(); 62 | } 63 | catch (Exception e) 64 | { 65 | Console.WriteLine(e.ToString()); 66 | Console.Read(); 67 | } 68 | } 69 | 70 | private static void BeginReceiveData(object handler) 71 | { 72 | EncapsPacket request; 73 | do 74 | { 75 | var objHandler = handler as Socket; 76 | request = ReceiveData(objHandler); 77 | if(request.Length==0 && request.Command!= (ushort)EncapsCommand.UnRegisterSession) continue; 78 | string txt; 79 | var remotePoint = ((System.Net.IPEndPoint)objHandler.RemoteEndPoint).Address; 80 | switch (request.Command) 81 | { 82 | case (ushort)EncapsCommand.RegisterSession: 83 | txt = string.Format("{0} {1}, {2}", remotePoint, EncapsCommand.RegisterSession, "success"); 84 | break; 85 | case (ushort)EncapsCommand.UnRegisterSession: 86 | txt = string.Format("{0} {1}", remotePoint, EncapsCommand.UnRegisterSession); 87 | break; 88 | default: 89 | txt = GetData(request.EncapsData); 90 | txt = string.Format("{0} {1}, {2}", remotePoint, request.Command, txt); 91 | break; 92 | } 93 | Console.WriteLine(txt); 94 | ReplyData(objHandler, txt); 95 | } while (!_stop && request.Command!= (ushort)EncapsCommand.UnRegisterSession); 96 | } 97 | 98 | private static EncapsPacket ReceiveData(Socket handler) 99 | { 100 | var bytes = new byte[_bufferSize]; 101 | var bytesRec = handler.Receive(bytes); 102 | var request = new EncapsPacket(); 103 | int tmp; 104 | if(bytesRec>0) 105 | request.Expand(bytes, 0, out tmp); 106 | return request; 107 | } 108 | private static void ReplyData(Socket handler, string data) 109 | { 110 | byte[] bytes = Encoding.Default.GetBytes(data); 111 | var reply = EncapsPacketFactory.CreateNOP(bytes); 112 | //var reply = new EncapsPacket(); 113 | //reply.EncapsData = bytes; 114 | //reply.Length = (ushort)data.Length; 115 | //reply.Command = (ushort) EncapsCommand.NOP; 116 | reply.Status = (uint)EncapsStatusCode.Success; 117 | var msg = reply.Pack(); 118 | handler.Send(msg); 119 | } 120 | private static string GetData(byte[] bytes) 121 | { 122 | var txt = Encoding.Default.GetString(bytes, 0, bytes.Length); 123 | return txt; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /EipNetServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EipNetServer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EipNetServer")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("13e8ea18-34de-4529-82dc-cbdaa8a60bac")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EipNet 2 | Demo Ethernet/IP Industrial Protocol 3 | --------------------------------------------------------------------------------