Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.Communication.Operators/TcpNetworkInitiator.cs @ 583

Last change on this file since 583 was 583, checked in by abeham, 17 years ago

Adding communication framework to branch 3.1 (ticket #278)

File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Net.Sockets;
5using System.Text;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.Communication.Data;
9
10namespace HeuristicLab.Communication.Operators {
11  public class TcpNetworkInitiator : OperatorBase {
12
13    public override string Description {
14      get { return @"Initiates a TCP socket, it opens one socket for sending and one socket for listening as specified in the configuration"; }
15    }
16
17    public TcpNetworkInitiator() {
18      AddVariableInfo(new VariableInfo("DriverConfiguration", "A configuration object", typeof(TcpNetworkDriverConfiguration), VariableKind.In));
19      AddVariableInfo(new VariableInfo("NetworkConnection", "A connection object", typeof(SocketData), VariableKind.New));
20    }
21
22    public override IOperation Apply(IScope scope) {
23      TcpNetworkDriverConfiguration config = GetVariableValue<TcpNetworkDriverConfiguration>("DriverConfiguration", scope, true);
24      SocketData socket = new SocketData();
25      socket.Initialize(config);
26      while (!socket.Connect()) ;
27
28      IVariableInfo info = GetVariableInfo("NetworkConnection");
29      if (info.Local)
30        AddVariable(new Variable(info.ActualName, socket));
31      else
32        scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), socket));
33
34      return null;
35    }
36  }
37}
Note: See TracBrowser for help on using the repository browser.