title: C# TCP Connection to Siemens S7 PLC - Network Newbie
body: <p>I want to establish a two-way communication setup between a PC and a s7-PLC.
  So far I've been successful setting this up one-way with the use of an open source driver found here:
  <a href="https://github.com/killnine/s7netplus" rel="nofollow noreferrer">https://github.com/killnine/s7netplus</a></p>
  
  <p>This driver allows me to tell the PC to fetch data from the PLC, and also write data. But the problem is I want to setup an onChanged event for specific PLC data, and the only way to currenly acheive that is to frequency poll the PLC's data until I notice it has changed. </p>
  
  <p>I would like it to be more interupt driven, so the PLC sends a signal to the PC asychronously when its data has changed, allowing a faster response, and less network traffic.</p>
  
  <p>So I found Siemens Open Communication Wizard, to basically configure a connection on the PLC side that can be referenced in the PLC code. I have setup the connection so the PLC is passive and looking for Port 2000:</p>
  
  <p><img src="https://i.stack.imgur.com/9trHN.png" alt="enter image description here"></p>
  
  <p>Now on my c# side, how would I establish connection, just using a socket?</p>
  
  <pre><code>// open the channel
  _mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  
  _mSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000);
  _mSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
  
  IPEndPoint server = new IPEndPoint(IPAddress.Parse(IP), 2000);
  _mSocket.Connect(server);
  </code></pre>
  
  <p>I'm really new to netowrking. If the PC is the active partner and I establish connection, I want to asychronously be able to accept data from the PLC,
  if I setup a socket.BeginRecieve() somewhere, can I still actively commuincate over the socket from PC->PLC or would it be stuck waiting in the BeginRecieve?</p>