473,545 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using sockets

Hi
I want to broadcast a message to all pc's on a lan via port 1002.
Can anyone tell me the best way of doing a general broadcast.

Thanks in advance

Nov 23 '05 #1
1 989

you can use the below class like this , if you set strIpadress to
"255.255.255.25 5" the message will be sent to all computers on the network
clsBc = New Broadcaster(str IpAdress,
CType(Integer.P arse(Configurat ionSettings.App Settings("BCSer verPort")),
Short), strmessage)

clsBc.SendMessa ge()

clsBc = Nothing

### start class code ###
Imports System.Net

Imports System.Net.Sock ets

Public Class Broadcaster

#Region "Delegates"

Delegate Sub MessageSuccess( )

Delegate Sub MessageFailure( )

#End Region

#Region "Private Fields"

Private _NetIPAddress As String

Private _Port As Int16

Private _BroadcastMessa ge As String

Private myClient As New System.Net.Sock ets.UdpClient

Private _Info As Byte()

'Points to MessageSuccess( )

Public Event MessageSent As MessageSuccess

'Points to MessageFailure

Public Event MessageFailed As MessageFailure

#End Region

#Region "Properties "

Public Property NetIPAddress() As String

Get

Return _NetIPAddress

End Get

Set(ByVal Value As String)

_NetIPAddress = Value

End Set

End Property

Public Property Port() As Int16

Get

Return _Port

End Get

Set(ByVal Value As Int16)

_Port = Value

End Set

End Property

Public Property BroadcastMessag e() As String

Get

Return _BroadcastMessa ge

End Get

Set(ByVal Value As String)

_BroadcastMessa ge = Value

End Set

End Property

#End Region

#Region "Methods"

'If this constructor is used, all you need to do is call SendMessage

Public Sub New(ByVal IP_Address As String, ByVal PortNumber As Int16, ByVal
Msg As String)

Me.NetIPAddress = IP_Address

Me.Port = PortNumber

Me.BroadcastMes sage = Msg

End Sub

'If this constructor is used, make sure you set the BroadcastMessag e

Public Sub New(ByVal IP_Address As String, ByVal PortNumber As Int16)

Me.NetIPAddress = IP_Address

Me.Port = PortNumber

End Sub

Public Sub SendMessage()
_Info = System.Text.Enc oding.UTF8.GetB ytes(Me.Broadca stMessage)

Dim EndPoint As New IPEndPoint(IPAd dress.Parse(Me. NetIPAddress), Me.Port)

Try

myClient.Send(M e._Info, Me._Info.Length , EndPoint)

RaiseEvent MessageSent()

Catch ex As System.Net.Sock ets.SocketExcep tion
RaiseEvent MessageFailed()

End Try

End Sub

#End Region

End Class

### end class code ###
regrds

Michel Posseth

"Starbuck" <ke*@kevsbox.co m> wrote in message
news:uu******** ******@TK2MSFTN GP10.phx.gbl...
Hi
I want to broadcast a message to all pc's on a lan via port 1002.
Can anyone tell me the best way of doing a general broadcast.

Thanks in advance

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5289
by: feel52 | last post by:
Below you'll find the code i'm working on. It's in a button click routine and hangs after 3 or 4 sometimes 5 loops done, probably in sock.receive(....). Some code was found here( on google i mean) but the amazing( at least for me) is that if i run the program step by step or i cancel the loop and run it by pressing the button again and...
3
4171
by: Raj | last post by:
I want to pass a C structure from a windows server to the C# client using the Sockets. Will there be requirements to cast the data types in the C# client?
3
1899
by: Mr Mind - Lion | last post by:
Please send me some sample for using Raw sockets. And also clearly specify that how can I set the ip header of the protocol. Please help me. Thanx.
0
323
by: Jason L James | last post by:
Hi All, I am trying to send information from my vb.Net app to a piece of hardware with an embedded TCP/IP controller using sockets. I can send information so the sockets are working but the data is garbage!!! It works if the ascii of the character I am sending
1
7375
by: crashed | last post by:
Hi, I am using C# in .NET 2.0 and im trying to read a stream from a socket. The code works on the first attempt but fails on subsequent attempts. It is in a multithreaded application. It seems the PlayerStream.Read() sets the PlayerSocket.Connected=false??? I am getting the following error: System.IO.IOException: Unable to read data from...
1
15610
by: verge | last post by:
hello everyone! how's it going? like everyone in here im in need of some help and good friendship along the way...take a look at this: //MODIFIED SO IT DEALS WITH WINDOWS FTP USING ACTIVE CONNECTION //IMPORTANT: the logic is NOT complete, the program works only once and disconnects or freeze //One needs to modify or rewrite the program...
2
1807
by: Robbert van Geldrop | last post by:
Hello, I have a client that consumes a WebService using a WSE 2.0 sp3 interface. I use a WebProxy as generated by VS.Net, based on a webService URL. Occasionaly when debugging I get an unhandled expection in disassembly code: "Connection was forcidbly closed by remote host" stack trace:
3
6623
by: jtagpgmr | last post by:
I need help coming up with a way to create a c# program to help me Telnet to a hostIP.. Any suggestions.. or a way to start..
4
2151
by: billie | last post by:
Hi all. I'm (re)writing an FTP server application by using asyncore/asynchat modules. FTP tipically got two different channels: command and data. I'm succesfully managing command channel through asynchat framework, but I'm not sure about how to manage data channel without using a thread/subprocess. Is there an optimal to do that? Can...
0
7453
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7742
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1865
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1007
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.