deez

Rcv/Send Packet

May 19th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Threading
  2. Imports System.Net.Sockets
  3. Imports System.IO
  4. Imports System.Net
  5.  
  6.  
  7. Public Class Packets
  8.    Shared Dim Client As UdpClient
  9.    Shared Dim Rcv As IPEndPoint
  10.  
  11.  
  12.    Public Shared Sub Main()
  13.    Dim Thread As Thread = New Thread(New ThreadStart(AddressOf WaitForPackets))
  14.    Dim Packet As String = "Client"
  15.    Dim Data As Byte() = System.Text.Encoding.ASCII.GetBytes(Packet)
  16.    Dim Host As String = "localhost"
  17.       Rcv = New IPEndPoint(New IPAddress(0), 0)
  18.       Client = New UdpClient(5001)
  19.       Thread.Start()
  20.         Console.WriteLine("Packet envoyer à " & Host & ".")
  21.         Client.Send(Data, Data.Length, Host, 5000)
  22.         Console.WriteLine("Le packet " & Packet & " est envoyer avec succès !")
  23.    End Sub
  24.    
  25.    Shared Public Sub PacketTime()
  26.       While True
  27.          Dim Data As Byte() = Client.Receive(Rcv)
  28.          Console.WriteLine("Packet reçu :" & _
  29.          vbCrLf & "Taille : " & Data.Length & vbCrLf & _
  30.          System.Text.Encoding.ASCII.GetString(Data))
  31.     End While
  32.  
  33.    End Sub
  34.    
  35. End Class
Advertisement
Add Comment
Please, Sign In to add comment