/// <summary> /// Faz a conexão com o Server UDP /// </summary> private void Conectar() { int RemotePort = 0; int LocalPort = 0; if (int.TryParse(txtRemotePort.Text, out RemotePort) && int.TryParse(txtLocalPort.Text, out LocalPort)) { // Conectar em BroadCast if (rdBroadCast.Checked) { UDP.Connect(IPAddress.Broadcast, RemotePort, LocalPort); } else if (rdAny.Checked) { UDP.Connect(IPAddress.Any, RemotePort, LocalPort); } // Conecta a um IP Remoto Especificado. else { UDP.Connect(txtIP.Text, RemotePort, LocalPort); } // UDP.DataReceivedInBackGround += UDP_DataReceivedInBackGround; // btnConnect.Text = "Disconnect"; btnSend.Enabled = true; } }
private async void Search_TCP232() { // Classe usada para listar o ARP (Todos os IP's registrados no gateway) ArpHelper arp = new ArpHelper(); // Gera a lista ARP com IPs, MACs e Types dos Equipamentos Registrados na Rede. listArp = arp.GetArpResult(); // byte[] searchCommand = { 0xFF, 0x01, 0x01, 0x02 }; // byte[] basicCommmand = { 0x55, 0xC6 }; // lstListDevices.Items.Clear(); // Roda a lista ARP enviando o comando de "Search" na porta 1901. foreach (var device in listArp) { lstListDevices.Items.Add(GetListViewItem(device)); // Conecta via UDP ao Device UDP.Connect(device.Ip, 1901, 1901); // UDP.DataReceivedInBackGround += UDP_DataReceivedInBackGround; // Envia um comando de busca, caso o device responda corretamente, então trata-se de um módulo USR-TCP232 UDP.Send(searchCommand); // await Task.Delay(800); // UDP.DataReceivedInBackGround -= UDP_DataReceivedInBackGround; // UDP.Disconnect(); // await Task.Delay(50); } }
public override void Initialize() { base.Initialize(); Mod = GetInstance <TManagerAgent>(); // Initialize connection to tOverseer ClientTCP = new ClientTCP(Mod.OverseerAddress, Mod.OverseerTCPPort); ClientTCP.OnMessageReceived += ParseServerMessage; bool success = ClientTCP.TryConnect(); if (success) { ClientTCP.StartListening(); ClientTCP.SendMessage("Terraria greets you via TCP."); } ClientUDP = new ClientUDP(Mod.OverseerAddress, Mod.OverseerUDPPort); ClientUDP.OnMessageReceived += ParseServerUDPMessage; ClientUDP.Connect(); ClientUDP.StartListening(); ClientUDP.SendMessage("Terraria greets you via UDP."); }