3 Replies - 379 Views - Last Post: 15 February 2013 - 08:19 AM Rate Topic: -----

#1 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Work-Around For Permission w/ UdpClient.Receive()

Posted 14 February 2013 - 12:28 PM

Hey guys, I'm working on a Messenger system and I'm using UDP on the client side to detect which host the server is running from. It works fine but on Windows 7 systems administrator privileges are needed to listen on ports. The machines the clients are to run on require the Administrator password to do so. It does not however need the administrator password on the TCP side since the server is doing the listening. Is there another method or solution for this? Would not mind another method of detecting the server either. By the way it's a LAN based messenger.

Is This A Good Question/Topic? 0
  • +

Replies To: Work-Around For Permission w/ UdpClient.Receive()

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,017
  • Joined: 05-May 12

Re: Work-Around For Permission w/ UdpClient.Receive()

Posted 14 February 2013 - 12:53 PM

Sort of a tangential question. If you are using UDP, then more likely than not, you have a peer-to-peer system. Why do you need a server? Typically, when you have server, then you have the clients make TCP connections to the server.
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5805
  • View blog
  • Posts: 12,644
  • Joined: 16-October 07

Re: Work-Around For Permission w/ UdpClient.Receive()

Posted 14 February 2013 - 01:10 PM

UDP? Are you doing some kind of broadcast for discover? If not, you should. If you are, what's the code? It's odd you'd get locked down for that. Perhaps you want a different port; some have specific security considerations.

Alternates? On a Windows domain you could just ask active directory. Put servers that are available in a group.
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Work-Around For Permission w/ UdpClient.Receive()

Posted 15 February 2013 - 08:19 AM

@Skydiver No it's not a peer-to-peer system. A central server is involved that receives all messages and sends them to the appropriate client.

@baavgai Yep the UDP is just for discovery purposes. Wanted to save my users the hassle of selecting the host because they aren't computer savie. Even the word Port baffles them so I decided to let the client send out a UDP datagram to all the computers on the network and whichever sends back the right response has the server. The code I was using is this:
private void Search()
{

	UdpClient udp_client = new UdpClient(9999); //new UdpClient(Protocol.IM_Message.UDP_PORT);
	
	IPEndPoint ip_endpoint;// = new IPEndPoint(IPAddress.Any, 0);
	byte[] data = ASCIIEncoding.ASCII.GetBytes(IM_Message.MESSAGE_TYPE_HELLO);

	foreach (KeyValuePair<string, IPAddress> p in hostToIP)
	{
		ip_endpoint = new IPEndPoint(p.Value, 9999);

		UdpState s = new UdpState();
		s.e = ip_endpoint;
		s.u = udp_client;

		messageReceived = false;
		udp_client.Connect(ip_endpoint);
		udp_client.Send(data, data.Length);
		udp_client.BeginReceive(new AsyncCallback(ReceiveCallback), s);

		Thread.Sleep(300);
		if (messageReceived)
		{
			
			server = p.Value;
			break;
		}
	}
}


Fairly new to this side of C# so bare with me. The application requested administrator rights when the BeginReceive method is called.

After doing some reading I took a whole new route. I decided to add the client and server to the same MulticastGroup. Turns out administrative rights aren't required with that method so it's working now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1