I am very new to VB.net 2008, and i need to make a program where The client sends a number to the server, which notifies the client that it recieved that specific number, which then causes the client to automatically send a new number and wait for the notification before it sends again....
If anybody can help out, it would be greatly appreciated. Coming from VB 6.0 i am getting very confused with the way it is done in .NET.
This is my Current Code:
Server:
Imports System Code:
Imports System Imports System.Net Imports System.Net.Sockets Imports System.Text Public Class Server Public ipAddr As System.Net.IPAddress Private Sub receiver_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim t As New Threading.Thread(AddressOf listen) t.IsBackground = True t.Start() End Sub Private Sub receiver_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _ Handles Me.FormClosing If udp IsNot Nothing Then udp.Close() End Sub Private udp As Net.Sockets.UdpClient Private sendMessage As Net.Sockets.UdpClient Private Sub listen() Try udp = New Net.Sockets.UdpClient(6100) sendMessage = New Net.Sockets.UdpClient(6103) udp.EnableBroadcast = True Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6100) Do Dim b() As Byte = udp.Receive(ep) Me.Invoke(safeAddText, System.Text.Encoding.UTF32.GetString(b)) Loop Catch ex As Exception MsgBox(ex.Message) ' If udp IsNot Nothing Then udp.Close() End Try End Sub Private Delegate Sub delAddText(ByVal text As String) Private safeAddText As New delAddText(AddressOf AddText) Private Sub AddText(ByVal text As String) ListBox1.Items.Add(text) Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6101) Dim b() As Byte = System.Text.Encoding.UTF32.GetBytes(text) sendMessage.Send(b, b.Length, ep) End Sub End Class
Client:
Imports System.Net Code:
Imports System.Net Imports System.Net.Sockets Imports System.Text Imports Microsoft.VisualBasic.Strings Public Class Frmmain Public Const Payload As String = "OCX000000FFFFFF" Public Counter As Integer = 1 Public LastString As String Private Sub Frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim t As New Threading.Thread(AddressOf listen) t.IsBackground = True t.Start() End Sub Private udp As Net.Sockets.UdpClient Private sendMessage As Net.Sockets.UdpClient Private Sub listen() Try udp = New Net.Sockets.UdpClient(6101) udp.EnableBroadcast = True Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6101) Do Dim b() As Byte = udp.Receive(ep) Me.Invoke(safeAddText, System.Text.Encoding.UTF32.GetString(b)) Loop Catch ex As Exception MsgBox("here:" & ex.Message) ' If udp IsNot Nothing Then udp.Close() End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim udp As New Net.Sockets.UdpClient() udp.EnableBroadcast = True Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6100) Dim b() As Byte = System.Text.Encoding.UTF32.GetBytes("Recieved") udp.Send(b, b.Length, ep) End Sub Private Delegate Sub delAddText(ByVal text As String) Private safeAddText As New delAddText(AddressOf AddText) Private Sub AddText(ByVal text As String) If (text.ToString = LastString.ToString) Then Counter += 1 End If Listbox1.Items.Add(text) Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6101) Dim b() As Byte = System.Text.Encoding.UTF32.GetBytes(text) ' sendMessage.Send(b, b.Length, ep) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim udp As New Net.Sockets.UdpClient() udp.EnableBroadcast = True Dim ep As New Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 6100) LastString = Counter.ToString.PadRight(4, "X") & Payload Dim b() As Byte = System.Text.Encoding.UTF32.GetBytes(LastString) udp.Send(b, b.Length, ep) End Sub End Class
I would like the client to send packets in a sequence number that increases, ONLY increases when it gets the acknowledgement from the server that it recieved the sequence that the client sent. The payload attached never changes. If the server has not responded in 2 seconds that it recieved the sent sequence, it acknowledges the last sequence it received telling the client to send the same sequence number as it did before. And if the first one doesnt make it, the server acknowledges 0. I hope thats clear enough...
I also want the client to count how many times it needed to resend a packet twice or more before it got the acknowledgement from the server.
I think thats really all i need to change, and change the server from using a manual button and text from a textbox, to what i mentioned above.. If you can help me get these last bugs fixed i think ill be finished!
Thanks so much!




Reply With Quote