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]
# 1

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.

MikeFlasko at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

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.DoWork

Dim 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.LocalDomain

If Scope = IPScope.LocalDomain Then

RemoteIpEndPoint.Address = IPAddress.Broadcast

End If

Try

Do

' Suspend until a message returns on this socket from a remote host.

Dim receiveBytes As [Byte]() = mUDPClient.Receive(RemoteIpEndPoint)

'Stop loop if cancel was requested

If MyWorker.CancellationPending Then

'Used to flag the result MyWorker.CancellationPending (e.Canelled) = true. For Information only.

e.Cancel = True

Exit Do

End If

Dim returnData As String = System.Text.Encoding.ASCII.GetString(receiveBytes)

'Uses the report progress to return the message received

' Message is sent on ProgressChangedEventArgs.UserState

If RemoteIpEndPoint.Address.ToString <> Me.GetMyIP Then ' ******* This is the condition I suggest for your case******

MyWorker.ReportProgress(0, returnData)

End If

Loop

Catch ex As Exception

My.Computer.FileSystem.WriteAllText("BroadcastError.log", Now() & " - ReceiveMSG: " & ex.Message & vbCrLf, True)

End Try

End Sub

Hope it helps.

EduardoCoelho at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified