Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. Private Sub CmdClear_Click()
  2. TxtRcv.Text = ""
  3. End Sub
  4.  
  5. Private Sub CmdSend_Click()
  6. WinSock.RemoteHost = "255.255.255.255" 'ip do equipamento'
  7. WinSock.SendData TxtSend.Text
  8. End Sub
  9.  
  10. Private Sub WinSock_DataArrival(ByVal bytesTotal As Long)
  11. WinSock.GetData s$
  12. TxtRcv.Text = TxtRcv.Text + s$ + Chr$(13) + Chr$(10)
  13. End Sub
  14.  
  15. private static void Main(string[] args)
  16. {
  17. var host = IPAddress.Parse("192.168.25.200");
  18.  
  19. var hostep = new IPEndPoint(host, 3000);
  20.  
  21. var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified);
  22.  
  23. try
  24. {
  25. sock.Connect(hostep);
  26. }
  27. catch (SocketException e)
  28. {
  29. Console.WriteLine("Problem connecting to host");
  30. Console.WriteLine(e.ToString());
  31. sock.Close();
  32. return;
  33. }
  34.  
  35. try
  36. {
  37. sock.SendTo(Encoding.ASCII.GetBytes("V"), hostep);
  38. }
  39. catch (SocketException e)
  40. {
  41. Console.WriteLine("Problem sending data");
  42. Console.WriteLine(e.ToString());
  43. sock.Close();
  44. return;
  45. }
  46.  
  47. var receivingUdpClient = new UdpClient(3000);
  48.  
  49. try
  50. {
  51. var receiveBytes = receivingUdpClient.Receive(ref hostep);
  52.  
  53. var returnData = Encoding.ASCII.GetString(receiveBytes);
  54.  
  55. Console.WriteLine("Mensagem recebida " + returnData);
  56. }
  57. catch (Exception e)
  58. {
  59. Console.WriteLine(e.ToString());
  60. }
  61.  
  62. sock.Close();
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement