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 | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Net;
|
---|
4 | using System.Net.Sockets;
|
---|
5 | using System.Text;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Communication.Data;
|
---|
9 |
|
---|
10 | namespace 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.