#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.ServiceModel; using System.ServiceModel.Description; using HeuristicLab.PluginInfrastructure; using System.Net; namespace HeuristicLab.Grid { public partial class ServerForm : Form { private EngineStore jobStore; private GridServer server; private ServiceHost externalHost; private ServiceHost internalHost; public ServerForm() { InitializeComponent(); // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2 if (System.Environment.OSVersion.Version.Major >= 6) { externalAddressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8000/Grid/Service"; internalAddressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8001/Grid/JobStore"; } else { externalAddressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8000/Grid/Service"; internalAddressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8001/Grid/JobStore"; } jobStore = new EngineStore(); server = new GridServer(jobStore); Start(); } private void Start() { externalHost = new ServiceHost(server, new Uri(externalAddressTextBox.Text)); internalHost = new ServiceHost(jobStore, new Uri(internalAddressTextBox.Text)); ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior(); throttlingBehavior.MaxConcurrentSessions = 20; internalHost.Description.Behaviors.Add(throttlingBehavior); try { NetTcpBinding binding = new NetTcpBinding(); binding.MaxReceivedMessageSize = 100000000; // 100Mbytes binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements; binding.Security.Mode = SecurityMode.None; externalHost.AddServiceEndpoint(typeof(IGridServer), binding, externalAddressTextBox.Text); externalHost.Open(); internalHost.AddServiceEndpoint(typeof(IEngineStore), binding, internalAddressTextBox.Text); internalHost.Open(); } catch (CommunicationException ex) { MessageBox.Show("An exception occurred: " + ex.Message); externalHost.Abort(); internalHost.Abort(); } } private void statusUpdateTimer_Tick(object sender, EventArgs e) { waitingJobsTextBox.Text = jobStore.WaitingJobs+""; waitingResultsTextBox.Text = jobStore.WaitingResults+""; runningJobsTextBox.Text = jobStore.RunningJobs+""; } } }