private void MainServerForm_Load(object sender, EventArgs e) { TraceOps.LoadLog(); try { _name = "Server"; Services.PrepareSetService(_port); Services.SetService(typeof(ConnectionTable)); Services.SetService(typeof(MessageQueue)); _connectionTable = ConnectionTable.GetRemote("localhost", _port); _messageQueue = MessageQueue.GetRemote("localhost", _port); _taskManager = new TaskManager(ref _messageQueue, ref _name); _taskManager.Task += TaskManagerOnTask; var ci = new ConnectionTable.ClientInformation(_name); ci.SetGroup("server"); ci.SetIp(NetworkOps.GetIpString(HashOps.GetFqdn())); ci.SetPort(_port); _connectionTable.Set(_name, ci); LoadClientsTable(); LoadPlugIns(); } catch (Exception ex) { TraceOps.Out(ex.Message); } }
private void Register() { var ci = _connectionTable.Get(_name); //TODO Demo ci.SetApplicationNames(""); ci.SetIp(NetworkOps.GetIpString(HashOps.GetFqdn())); ci.SetPort(9091); _connectionTable.Set(_name, ci); }
private void LoadConnections(Connections connections) { foreach (Connection connection in connections.ConnectionList) { if (connection.name != "Server" && connection.ip != "unknown" && connection.port != 0) { IPHostEntry he = Dns.GetHostEntry(connection.ip); var dns = he.AddressList[1].ToString(); var ip = NetworkOps.GetIpString(dns); NetworkOps.SetUpClientConnectionConfig(ip, connection.port, _ip, _port); } } }
private void newConnectionToolStripMenuItem_Click_1(object sender, EventArgs e) { _newConnectionForm = new ConnectionForm() { TopLevel = true }; if (_newConnectionForm.ShowDialog() == DialogResult.OK) { var ip = NetworkOps.GetIpString(_newConnectionForm.textBoxUri.Text); var port = NetworkOps.GetPort(_newConnectionForm.textBoxPort.Text); var connected = NetworkOps.SetUpClientConnectionConfig(ip, port, _ip, _port); if (!connected) { MessageBox.Show("Cannot establish connection to network. Please try again.\r\n"); } } }
private void notifyIcon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { var btext = "No network connection"; try { btext = NetworkOps.GetIpString(HashOps.GetFqdn()); } catch (Exception) { btext = "No network connection"; } notifyIcon.ShowBalloonTip(1000, "Pace Configuration", btext, ToolTipIcon.None); } if (e.Button == MouseButtons.Right) { MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic); mi.Invoke(notifyIcon, null); } }
private void ConfigTasks() { try { Byte[] data; String responseData = String.Empty; var server = new TcpListener(IPAddress.Any, _port); server.Start(); while (_running) { Thread.Sleep(Threshold); while (!server.Pending()) { Thread.Sleep(Threshold); } TcpClient client = server.AcceptTcpClient(); NetworkStream stream = client.GetStream(); IPEndPoint remoteIpEndPoint = client.Client.RemoteEndPoint as IPEndPoint; IPEndPoint localIpEndPoint = client.Client.LocalEndPoint as IPEndPoint; if (remoteIpEndPoint != null) { TraceOps.Out(remoteIpEndPoint.Address + " : " + remoteIpEndPoint.Port); } if (localIpEndPoint != null) { TraceOps.Out(localIpEndPoint.Address + " : " + localIpEndPoint.Port); } while (client.Connected) { Thread.Sleep(Threshold); data = new Byte[1024]; var connectIp = ""; var connectPort = 0; Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); if (responseData != "") { if (responseData.IndexOf("<PORT>", StringComparison.Ordinal) > 0) { connectPort = Convert.ToInt32(NetworkOps.GetValue("PORT", responseData)); TraceOps.Out("Recived PORT: " + connectPort); } if (responseData.IndexOf("<IP>", StringComparison.Ordinal) > 0) { connectIp = NetworkOps.GetValue("IP", responseData); connectIp = NetworkOps.GetIpString(connectIp); TraceOps.Out("Recived IP: " + connectIp); } if (responseData.IndexOf("</XML>", StringComparison.Ordinal) > 0) { stream.Close(); client.Close(); if (connectIp != "" && connectPort != 0 && remoteIpEndPoint != null) { var e = new ChangedEventArgs(remoteIpEndPoint.Address.ToString(), connectPort); OnChanged(e); } TraceOps.Out("Recived End"); } } } TraceOps.Out("Close Stream and TCP Connection"); if (client.Connected) { stream.Close(); client.Close(); } } server.Stop(); } catch (Exception exception) { TraceOps.Out(exception.ToString()); } }