Click here to Skip to main content
15,889,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code for single client - server but i am confused how to convert it to multiple client-server in a LAN network.I have a project to connect pcs in a LAN network like colleges or cyber cafes and exchange data between the clients and the server.I want the code for UDP connection and in vb.net, i have pasted my code please help me.

What I have tried:

Udp Client:

VB.NET
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Module Module1
    Dim sock As UdpClient
    Dim ip As String = "127.0.0.1"
    Dim port As Int32 = 89

    Sub Main()
        Try
            sock = New UdpClient()
            sock.Connect(ip, port)
            Do
                Dim bytes() As Byte = Encoding.Default.GetBytes(Console.ReadLine)
                sock.Send(bytes, bytes.Length)
            Loop

        Catch ex As Exception
            Console.Write(ex.Message)
        End Try
    End Sub

End Module




Udp Server:


VB.NET
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Module Module1
    Dim sock As UdpClient
    Dim port As Int32 = 89
    Dim lpendp As IPEndPoint


    Sub Main()
        Try
            sock = New UdpClient(port)
            lpendp = New IPEndPoint(0, 89)
            Do
                Dim bytes() As Byte = sock.Receive(lpendp)
                Console.WriteLine(Encoding.Default.GetString(bytes))
            Loop
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub

End Module
Posted
Comments
Richard MacCutchan 28-Feb-16 9:24am    
You just need to add code in the server to manage all the incoming messages and keep a note of which client they come from. You can then ensure that all responses go back to the originator.
Member 12353779 28-Feb-16 10:02am    
how do i do that please help me i have very little knowledge about networking
Richard MacCutchan 28-Feb-16 10:26am    
Sorry I do not have a sample to show you. You just need to create some table or list to hold the details of each client. As each message arrives you add it to the input queue for its client. Then as messages are processed the responses are added to the output queues and then returned to the client. Try using Google to find some samples that others have created.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900