F
Feudalac!
I am trying to send an UDP packet and recive it.
The problem is that when the packet is recived, the thread stops and i
cant start it again...
here is the code
Public Class Form1
Public UDP_Reciving As System.Net.Sockets.UdpClient
Public IpSource As New
System.Net.IPEndPoint(System.Net.IPAddress.Any, 65433)
Public ThreadReceive As System.Threading.Thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim UDP_Sending As New System.Net.Sockets.UdpClient
UDP_Sending.Connect(System.Net.IPAddress.Parse("255.255.255.255"),
65432)
UDP_Sending.Send(System.Text.Encoding.ASCII.GetBytes(txtNewText.Text),
System.Text.Encoding.ASCII.GetBytes(txtNewText.Text).Length)
UDP_Sending.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MsgBox(ThreadReceive.IsAlive, MsgBoxStyle.Critical, "m")
-- on first click this box is 'true' but on every other click the box
is 'false'
i have checked with Ethereal - the packets are send successfuly...
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
UDP_Reciving = New System.Net.Sockets.UdpClient(65432)
ThreadReceive = New System.Threading.Thread(AddressOf
ReceiveMessages)
ThreadReceive.Start()
End Sub
Private Sub ReceiveMessages()
Dim receiveBytes As [Byte]() = UDP_Reciving.Receive(IpSource)
Dim BitDet As BitArray
BitDet = New BitArray(receiveBytes)
Dim strReturnData As String =
System.Text.Encoding.Unicode.GetString(receiveBytes)
Dim intI As Integer
Dim strTemp As String = ""
For intI = 0 To receiveBytes.Length - 1
strTemp = strTemp & Chr(receiveBytes(intI).ToString)
Next
SetText(IpSource.Address.ToString & " " & strTemp)
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub SetText(ByVal [text] As String)
If Me.txtHistory.InvokeRequired Then
Dim d As New SetTextCallback(AddressOfeudalac!
sfgsdfgsdfgf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.txtHistory.Text = [text]
End If
End Sub
End Class
The problem is that when the packet is recived, the thread stops and i
cant start it again...
here is the code
Public Class Form1
Public UDP_Reciving As System.Net.Sockets.UdpClient
Public IpSource As New
System.Net.IPEndPoint(System.Net.IPAddress.Any, 65433)
Public ThreadReceive As System.Threading.Thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim UDP_Sending As New System.Net.Sockets.UdpClient
UDP_Sending.Connect(System.Net.IPAddress.Parse("255.255.255.255"),
65432)
UDP_Sending.Send(System.Text.Encoding.ASCII.GetBytes(txtNewText.Text),
System.Text.Encoding.ASCII.GetBytes(txtNewText.Text).Length)
UDP_Sending.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MsgBox(ThreadReceive.IsAlive, MsgBoxStyle.Critical, "m")
-- on first click this box is 'true' but on every other click the box
is 'false'
i have checked with Ethereal - the packets are send successfuly...
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
UDP_Reciving = New System.Net.Sockets.UdpClient(65432)
ThreadReceive = New System.Threading.Thread(AddressOf
ReceiveMessages)
ThreadReceive.Start()
End Sub
Private Sub ReceiveMessages()
Dim receiveBytes As [Byte]() = UDP_Reciving.Receive(IpSource)
Dim BitDet As BitArray
BitDet = New BitArray(receiveBytes)
Dim strReturnData As String =
System.Text.Encoding.Unicode.GetString(receiveBytes)
Dim intI As Integer
Dim strTemp As String = ""
For intI = 0 To receiveBytes.Length - 1
strTemp = strTemp & Chr(receiveBytes(intI).ToString)
Next
SetText(IpSource.Address.ToString & " " & strTemp)
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub SetText(ByVal [text] As String)
If Me.txtHistory.InvokeRequired Then
Dim d As New SetTextCallback(AddressOfeudalac!
sfgsdfgsdfgf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.txtHistory.Text = [text]
End If
End Sub
End Class