broadcast message to all clients
hi,
I'm trying to develop a pgm that broadcasts the message to all clients except to the sender.
At present , every client is talking to the server and get the reply back.
i'm using TCP/IP Protocol.
How to implement broadcasting feature? If anybody knows the relatedlink, kindly post it.
Thank You!
[335 byte] By [
ar_pad] at [2007-12-25]
With the UDP protocol you can send a packet so that all workstations on the network will see it. (TCP doesn't allow broadcasting.)
To send broadcast packets, you must first enable the Broadcast option with the setsocketoption() method on the socket you will use to send the broadcast. Then you send packets out using a special broadcast address (for IPv4 that is 255.255.255.255)
Another option you may want to investigate is multicasting.
Take a look at the class I created. It may help you. Here is the link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=991129&SiteID=1
after you receive the message under mbgWorker1_DoWork you can compare the sender IP address with the local machine address and only raise the progresschange event (reportprogress) if they are different. Something like this:
Private
Sub mbgWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles mbgWorker1.DoWorkDim MyWorker As System.ComponentModel.BackgroundWorker = CType(sender, System.ComponentModel.BackgroundWorker)Dim Scope As IPScope = CType(e.Argument, IPScope)Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) 'Listen to all IPs as default'Restric listener to local domain if Scope set to IPScope.LocalDomainIf Scope = IPScope.LocalDomain ThenRemoteIpEndPoint.Address = IPAddress.Broadcast
End IfTryDo' Suspend until a message returns on this socket from a remote host.Dim receiveBytes As [Byte]() = mUDPClient.Receive(RemoteIpEndPoint)'Stop loop if cancel was requestedIf MyWorker.CancellationPending Then'Used to flag the result MyWorker.CancellationPending (e.Canelled) = true. For Information only.e.Cancel =
TrueExit DoEnd IfDim returnData As String = System.Text.Encoding.ASCII.GetString(receiveBytes)'Uses the report progress to return the message received' Message is sent on ProgressChangedEventArgs.UserStateIf RemoteIpEndPoint.Address.ToString <> Me.GetMyIP Then ' ******* This is the condition I suggest for your case******MyWorker.ReportProgress(0, returnData)
End IfLoopCatch ex As ExceptionMy.Computer.FileSystem.WriteAllText("BroadcastError.log", Now() & " - ReceiveMSG: " & ex.Message & vbCrLf, True)End TryEnd Sub
Hope it helps.