This repository was archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (77 loc) · 3.39 KB
/
Copy pathProgram.cs
File metadata and controls
86 lines (77 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using ProblemLib.API;
using ProblemLib.DataModel;
using ProblemLib.Logging;
namespace ProblemController
{
class Program
{
// Basic structure for problem controller
static void Main(string[] args)
{
// NOTE this is an implementation for testing only!
var console = new ConsoleLogger();
GlobalLogger.AttachLogger(console);
console.Run();
TcpClient client = new TcpClient();
try
{
client.Connect("localhost", 17924);
}
catch (Exception x)
{
GlobalLogger.SendLogMessage("Error", "Failed to connect to distribution server: {0}", x.Message);
console.Stop();
return;
}
var s = client.GetStream();
var bw = new BinaryWriter(s);
var br = new BinaryReader(s);
var r = new Random();
try
{
bw.Write(ControlCodes.SendingConfiguration);
var c = new DistributionConfiguration();
c.ProblemID = Guid.NewGuid();
c.ControllerServer = IPAddress.Parse("127.0.0.1");
c.ControllerServerPort = 3879;
c.RedisServer = IPAddress.Parse("192.168.2.31");
c.RedisServerPort = 6379;
c.OsrmServer = IPAddress.Parse("192.168.2.31");
c.OsrmServerPort = 5000;
c.RandomSeed = 1234567;
c.Workers = new[] { new Worker() { WorkerID = 0 }, new Worker() { WorkerID = 1 }, new Worker() { WorkerID = 2 } };
c.Tasks = new[] {
new Task(0, 1111.1111F, 2222.2222F), new Task(0, 1111.1111F, 2222.2222F),new Task(0, 1111.1111F, 2222.2222F) ,new Task(0, 1111.1111F, 2222.2222F),
new Task(0, 5511.1111F, 5522.2222F), new Task(0, 5511.1111F, 5522.2222F),new Task(0, 5511.1111F, 5522.2222F) ,new Task(0, 5511.5511F, 5522.2222F),
new Task(0, 8811.1111F, 2222.2222F), new Task(0, 8811.1111F, 2222.2222F),new Task(0, 8811.1111F, 2222.2222F) ,new Task(0, 8811.1111F, 2222.2222F)
};
c.WriteToStream(bw);
while (client.Available < 2) ;
UInt16 ctrl = br.ReadUInt16();
if (ctrl == ControlCodes.Acknowledge)
GlobalLogger.SendLogMessage("ControllerEvent", "Distribution server replied with ACK!");
else if (ctrl == ControlCodes.Error)
{
while (client.Available < 12) ; // wait for data
UInt32 errcode = br.ReadUInt32();
DateTime ts = new DateTime(br.ReadInt64());
GlobalLogger.SendLogMessage("DistributionError", "Distribution server reported error {0} at {1}:{2}:{3}.{4}", errcode, ts.Hour, ts.Minute, ts.Second, ts.Millisecond);
}
}
finally
{
bw.Write(ControlCodes.TerminateConnection); // emulate disconnect code
client.Close();
console.Stop(true);
}
Console.ReadKey();
}
}
}