473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Broadcast

GTi
I need a code snippet for sending a message to all computers located on
the same IP subnet.
This is only a simple message like; "Here I am"
I'm developing a server/client application.
Instead of configuration of each clients where the server is located I
want the server to broadcast a simple message that the server is
present.
This solution must work on a workgroup and domain even if the clients
are on different domain/workgroup.
Any ideas?

Aug 9 '06 #1
7 2286
Use Messaging Service

see sample there
http://groups.google.com/group/micro...732c4ebc45dde0

Take into account that this service should be run on windows machines

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"GTi" wrote:
I need a code snippet for sending a message to all computers located on
the same IP subnet.
This is only a simple message like; "Here I am"
I'm developing a server/client application.
Instead of configuration of each clients where the server is located I
want the server to broadcast a simple message that the server is
present.
This solution must work on a workgroup and domain even if the clients
are on different domain/workgroup.
Any ideas?

Aug 9 '06 #2
GTi
Michael Nemtsev wrote:
Use Messaging Service

see sample there
http://groups.google.com/group/micro...732c4ebc45dde0

Take into account that this service should be run on windows machines

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"GTi" wrote:
I need a code snippet for sending a message to all computers located on
the same IP subnet.
This is only a simple message like; "Here I am"
I'm developing a server/client application.
Instead of configuration of each clients where the server is located I
want the server to broadcast a simple message that the server is
present.
This solution must work on a workgroup and domain even if the clients
are on different domain/workgroup.
Any ideas?
Nice :-)
But what about recieving this messages on the client?

Aug 9 '06 #3
Hello GTi,

GNice :-)
GBut what about recieving this messages on the client?

On windows platform (since NT) you've got it automatically if Messaging service
is started

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 9 '06 #4
GTi

Michael Nemtsev wrote:
Hello GTi,

GNice :-)
GBut what about recieving this messages on the client?

On windows platform (since NT) you've got it automatically if Messaging service
is started

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Ahh - The Messanger service.
Well - that was not what I was thinking about.
I was more thinking about "low level" programming in C# with winsock
and UDP.
Like
http://www.c-sharpcorner.com//Code/2...lticasting.asp
But I need more samples about this.

Aug 9 '06 #5
GTi
Most of the samples I have found the target (server) is specified with
the IP address or hostname.
But I don't know where the target is, so I want to broadcast a message
to all IP adresses on the local subnet. If any of computer on the local
subnet IS the server it will answer back with UDP message. The
computers can be on different domain or workgroup. Target is Windows.

SERVER:
The server is located on any computer on the local subnet listen for a
UDP message on a specified address (port 10000). If it recieves a
"HELLO" message it will broadcast a message to the subnet saying "HERE
I AM" (on port 10001). In that way the client and all other clients
know where the server is located.

CLIENTS:
Clients can be started on any computer located in a subnet. This client
don't know if and where the server is located so it begins sending a
UDP message to all computers on a subnet (on port 10000). It also
listen for UDP messages (on port 10001). When it recieves a message on
port 10001 it know where the server is located, even if it have not
asked about it.

The UDP port 10000 is for the server - listen for clients messages
The UDP port 10001 is for the clients - listen for server messages.

Aug 9 '06 #6
Hello GTi,

as I understand you don't want to write any client app to install in on user?
In that case the only way is to use messanger service

Else you are free to use any IPC approaches - sockets, Pipes, Remoting, SOAP,
dcom

GMost of the samples I have found the target (server) is specified
Gwith
Gthe IP address or hostname.
GBut I don't know where the target is, so I want to broadcast a
Gmessage
Gto all IP adresses on the local subnet. If any of computer on the
Glocal
Gsubnet IS the server it will answer back with UDP message. The
Gcomputers can be on different domain or workgroup. Target is Windows.
GSERVER:
GThe server is located on any computer on the local subnet listen for
Ga
GUDP message on a specified address (port 10000). If it recieves a
G"HELLO" message it will broadcast a message to the subnet saying
G"HERE
GI AM" (on port 10001). In that way the client and all other clients
Gknow where the server is located.
GCLIENTS:
GClients can be started on any computer located in a subnet. This
Gclient
Gdon't know if and where the server is located so it begins sending a
GUDP message to all computers on a subnet (on port 10000). It also
Glisten for UDP messages (on port 10001). When it recieves a message
Gon
Gport 10001 it know where the server is located, even if it have not
Gasked about it.
GThe UDP port 10000 is for the server - listen for clients messages
GThe UDP port 10001 is for the clients - listen for server messages.
G>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 9 '06 #7
GTi
I have now found out how I can do it.
Just to show what my solution is.
(no comments is available . this is just a raw working program)
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

class Program
{
public static bool done=false;

static void Main(string[] args)
{
Thread listenThread = new Thread(new
ThreadStart(Program.DoListen));
Thread serverThread = new Thread(new
ThreadStart(Program.DoServer));
listenThread.Start();
serverThread.Start();

Console.ReadKey();
done = true;
}
/// <summary>
///
/// </summary>
public static void DoListen()
{
bool done = false;
UdpClient listener = new UdpClient(11000);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 11000);

//Console.WriteLine("CLIENT: Waiting for broadcast");
while(!done)
{
try
{
byte[] bytes = listener.Receive(ref groupEP);
Console.WriteLine("CLIENT: From {0} - {1}\n",
groupEP.ToString(), Encoding.ASCII.GetString(bytes, 0, bytes.Length));
} catch(Exception e) { Console.WriteLine("CLIENT:
"+e.ToString()); }
}
listener.Close();
}
/// <summary>
///
/// </summary>
public static void DoServer()
{
String strHostName = Dns.GetHostName();
//Console.WriteLine("SERVER: Local Machine's Host Name: " +
strHostName);
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;

while(!done)
{
for(int i = 0; i < addr.Length; i++)
{
string IPAdd = addr[i].ToString();
string[] IPAddresses = IPAdd.Split(new Char[] { '.' });
string IPAddr1 = IPAddresses[0];
string IPAddr2 = IPAddresses[1];
string IPAddr3 = IPAddresses[2];
// Console.WriteLine("SERVER: IP Address {0} ", IPAdd);
for(int a = 1; a <= 4; a++)
{
string IP = "255.255.255.255";
if(a == 2) IP = IPAddr1 + ".255.255.255";
if(a == 3) IP = IPAddr1 + "." + IPAddr2 + ".255.255";
if(a == 4) IP = IPAddr1 + "." + IPAddr2 + "." + IPAddr3 +
".255";
try
{
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
IPAddress broadcast = IPAddress.Parse(IP);
byte[] sendbuf = Encoding.ASCII.GetBytes("HELLO FROM " +
IPAdd + " subnet " + IP);
IPEndPoint ep = new IPEndPoint(broadcast, 11000);
s.SendTo(sendbuf, ep);
s.Close();
Thread.Sleep(1000);
} catch { };
}
}
}
}


}

Aug 11 '06 #8

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

Similar topics

0
by: Damir Hakimov | last post by:
Hi All! I'm writing a small programm which must send and service UDP broadcast packets. As start of it I looked at /usr/share/doc/python2.4/Examples/Demo/sockets/broadcast.py ...
6
by: pekspro | last post by:
I need some code that gets the address from a server. I read somewhere that you could do this by starting some broadcast server using UDP. The client should send an broadcast message, and when the...
8
by: Frank Esser | last post by:
Hello! I have got machines that answer a certain UDP broadcast request with certain information about them. Some years ago I wrote a VB6 application that just sent out this UDP broadcast...
2
by: gregory_may | last post by:
First the research links: IPv6 spec (look for 'jumbo payload'): http://www.cs-ipv6.lancs.ac.uk/ipv6/documents/rfcs/archive/rfc1883.txt IPv6 Sample C# Client/Server...
2
by: Shawn G. | last post by:
I'm going around in circles here and need some help. Scenario: I am using (have used) either the UDPClient class or Sockets class to broadcast some bytes to 255.255.255.255 (udp protocol). Upon...
2
by: Gunnar_Frenzel | last post by:
Hello, this might be an easy question, but I don't have any handy solution at hand. I have an application that is supposed to send UDP broadcast. So far so easy, I did: Socket sockSendBroadcast...
3
Sagittarius
by: Sagittarius | last post by:
Hi there. I have a problem concerning an UDP socket in C++ (Winsock). The next paragraphs is merely to explain the system I am working on. If U want to skip it, I have marked the question in...
9
by: Irmen de Jong | last post by:
Hello Sorry this might be a bit offtopic but I don't really know where else to post this question. If you could point me in the right direction that is much appreciated. I'm running into a...
2
by: Mali Findik | last post by:
Hi @ll, i've got problems with sending an UDP broadcast datagramm over two network interfaces. The code is like this: <Code> UdpClient client = new UdpClient(); IPEndPoint remoteEndPoint =...
1
by: raviskar | last post by:
Hi, I have a problem in receiving UDP broadcast data. We have a simple application which listens for the UDP broadcast data from the external servers. We can receive the UDP broadcast data from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.