|
From: Lloyd Dupont on 17 Jun 2008 10:33 I think Vista might be the culprit.... Anyway, could anyone share with me how to send some data over UDP and recieve it? Now it's not working, and I have no clue if it's the sending or recieving or both which fails.... Anyway I have simple code like that: === send ==== public void Send(byte[] data, IPEndPoint to) { using (Socket sock = new Socket(to.AddressFamily, SocketType.Dgram, ProtocolType.Udp)) sock.SendTo(data, SocketFlags.None, to); } === recieve === void Receiving() { byte[] rbuf = new byte[1 << 14]; using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) while (true) { EndPoint rep = new IPEndPoint(IPAddress.Any, 0); int read = sock.ReceiveFrom(rbuf, ref rep); Recieved(rbuf, read, rep); } } void Recieved(byte[] buf, int nRead, EndPoint where) { Console.WriteLine("Recieved {0} byte(s) from {1}", nRead, where); } ===========
From: Lloyd Dupont on 17 Jun 2008 10:58 Never mind,I found it! I should also (in the listening code) sock.Bind(new IPEndPoint(IPAddress.Any, aPort)) Pay attention to 'aPort' I should use the same port for target IPEndPoint when sending data
From: Peter Duniho on 17 Jun 2008 11:21 On Tue, 17 Jun 2008 07:33:00 -0700, Lloyd Dupont <ld(a)galador.removeme.net> wrote: > I think Vista might be the culprit.... > Anyway, could anyone share with me how to send some data over UDP and > recieve it? > Now it's not working, and I have no clue if it's the sending or > recieving or both which fails.... Usually it's a firewall or NAT router issue. The first step is to test the code on a single machine (both sending and receiving), to eliminate the possibility of a router causing issues (though you may still have to deal with it later). Vista and XP SP2 both come with a firewall that's enabled by default. Though, I was under the impression that Vista would prompt you if it detected a need to change the firewall settings based on what the code's doing. The code you posted doesn't look to me as though it has any significant errors. Personally, I wouldn't define buffer sizes in terms of left-shifts, and I'd spell the word "receive" correctly, but neither of those issues should be a direct problem here. :) Pete
From: Lloyd Dupont on 17 Jun 2008 19:21 Thanks for correcting me on Receive, I hought it was the contrary (Recieve) for a long time now! Other than that I like to define size as left shift, a matter of habit I suppose. In fact it was my bug and a strange "Vista issue". As soon I thought of trying my program as an administrator, it threw an error which show me the problem: sock.Bind() should be called prior to sock.RecieveFrom() As to why it fails silently on Vista when ran as user, it is a mystery! "Peter Duniho" <NpOeStPeAdM(a)nnowslpianmk.com> wrote in message news:op.ucwflyt08jd0ej(a)petes-computer.local... > On Tue, 17 Jun 2008 07:33:00 -0700, Lloyd Dupont <ld(a)galador.removeme.net> > wrote: > >> I think Vista might be the culprit.... >> Anyway, could anyone share with me how to send some data over UDP and >> recieve it? >> Now it's not working, and I have no clue if it's the sending or >> recieving or both which fails.... > > Usually it's a firewall or NAT router issue. The first step is to test > the code on a single machine (both sending and receiving), to eliminate > the possibility of a router causing issues (though you may still have to > deal with it later). Vista and XP SP2 both come with a firewall that's > enabled by default. Though, I was under the impression that Vista would > prompt you if it detected a need to change the firewall settings based on > what the code's doing. > > The code you posted doesn't look to me as though it has any significant > errors. Personally, I wouldn't define buffer sizes in terms of > left-shifts, and I'd spell the word "receive" correctly, but neither of > those issues should be a direct problem here. :) > > Pete
|
Pages: 1 Prev: Relationship between versions of .Net Framework Next: Recovering the First DC - HELP |