UdpClient.Receive never receives anything????

M

Morten Overgaard

Hi

I'm listening on the SysLog port (514) through UDP. The problem is that I am
not receiving anything nut I know that i get messages on the port. When I
use KIWI to listen on the same port via UDP tons of messages arrive.. What
am I'm doing wrong

My code looks like the following...

private UdpClient udpClient;

private IPEndPoint IPEnd;

private void button1_Click(object sender, System.EventArgs e)

{

udpClient = new UdpClient( 514);


udpClient.Connect(Dns.GetHostByName(), 514);

IPEnd = new IPEndPoint( IPAddress.Any,0);

byte[] recv = udpClient.Receive( ref IPEnd ); // <<<<< I NEVER GET PAST THIS
STATEMENT - receive is waiting for ever???????

MessageBox.Show( Encoding.ASCII.GetString( recv ));

}



REgards Morten
 
J

Jip from Paris

You use the UdpClient.Connect method. This tells the framework that you will
only accept incoming UDP packets from the designated host/port couple when
later calling UdpClient.Receive.
The strange thing is the first argument to your Connect method. The
GetHostByName method requires a single argument and your code should not
compile like this. I assume this is a typo and you are actually invoking the
Dns.GetHostName() method.

Consequently, you are saying that you are willing to receive UDP packets
originating from port 514 of the same machine as the one you are listening
from. Pretty useless isn't it ?
 
M

Morten Overgaard

The strange thing is the first argument to your Connect method. The
GetHostByName method requires a single argument and your code should not
compile like this

1) Yup it was a typo

Consequently, you are saying that you are willing to receive UDP packets
originating from port 514 of the same machine as the one you are listening
from. Pretty useless isn't it ?

2) The reason for listening on the local machine is because the firewall are
generating/Sending SysLog messages to this particular local machine.

but this still does not explain while I do not get any messages - when I can
see them arrive on UDP port 514 using KIWI??

regards Morten

Jip from Paris said:
You use the UdpClient.Connect method. This tells the framework that you will
only accept incoming UDP packets from the designated host/port couple when
later calling UdpClient.Receive.
The strange thing is the first argument to your Connect method. The
GetHostByName method requires a single argument and your code should not
compile like this. I assume this is a typo and you are actually invoking the
Dns.GetHostName() method.

Consequently, you are saying that you are willing to receive UDP packets
originating from port 514 of the same machine as the one you are listening
from. Pretty useless isn't it ?

Morten Overgaard said:
Hi

I'm listening on the SysLog port (514) through UDP. The problem is that
I
am
not receiving anything nut I know that i get messages on the port. When I
use KIWI to listen on the same port via UDP tons of messages arrive.. What
am I'm doing wrong

My code looks like the following...

private UdpClient udpClient;

private IPEndPoint IPEnd;

private void button1_Click(object sender, System.EventArgs e)

{

udpClient = new UdpClient( 514);


udpClient.Connect(Dns.GetHostByName(), 514);

IPEnd = new IPEndPoint( IPAddress.Any,0);

byte[] recv = udpClient.Receive( ref IPEnd ); // <<<<< I NEVER GET PAST THIS
STATEMENT - receive is waiting for ever???????

MessageBox.Show( Encoding.ASCII.GetString( recv ));

}



REgards Morten
 
D

Dim

try this instead (Asynchronous callbacks)

public delegate void DataArrivalHandler(object sender, byte[] data);

public class UDPListener

{

private Socket Sock;

private byte[] buff = new byte[1024];

public event DataArrivalHandler OnDataArrival;

public UDPListener(int port)

{

Sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);

IPEndPoint ippe = new IPEndPoint(IPAddress.Any, port);

Sock.Bind(ippe);

Sock.BeginReceive(buff, 0, 1024, SocketFlags.None, new
AsyncCallback(this.OnReceive), Sock);

}

private void OnReceive(IAsyncResult ar)

{

Socket s1 = (Socket) ar.AsyncState;

s1.EndReceive(ar);


if (! (this.OnDataArrival == null) )

this.OnDataArrival(this, buff);

buff = new byte[1024];

s1.BeginReceive(buff, 0, 1024, SocketFlags.None, new
AsyncCallback(this.OnReceive), s1);

}

}
 
J

Jeffrey Tan[MSFT]

Hi Morten,

If you want to listen to the 514 port, you does not need to connect to the
address.
You can simply do like this:

try
{
UdpClient udpClient;
IPEndPoint IPEnd;

udpClient = new UdpClient( 514);

IPEnd = new IPEndPoint( IPAddress.Any,514);

byte[] recv = udpClient.Receive( ref IPEnd ); // <<<<< I NEVER GET PAST
THIS
string str=Encoding.Unicode.GetString(recv);
Console.WriteLine(str);
}
catch(Exception ex)
{
Console.WriteLine (ex.Message );
}

I have downloaded Kiwi Syslog Daemon, when I sent text message to local
host, my
application succeeded receiving the data.

If there is still any problem, please feel free to let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Morten Overgaard" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: UdpClient.Receive never receives anything????
| Date: Tue, 26 Aug 2003 13:01:08 +0200
| Lines: 82
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 213.129.10.164
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:179388
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| >The strange thing is the first argument to your Connect method. The
| >GetHostByName method requires a single argument and your code should not
| >compile like this
|
| 1) Yup it was a typo
|
|
| >Consequently, you are saying that you are willing to receive UDP packets
| >originating from port 514 of the same machine as the one you are
listening
| >from. Pretty useless isn't it ?
|
| 2) The reason for listening on the local machine is because the firewall
are
| generating/Sending SysLog messages to this particular local machine.
|
| but this still does not explain while I do not get any messages - when I
can
| see them arrive on UDP port 514 using KIWI??
|
| regards Morten
|
| | > You use the UdpClient.Connect method. This tells the framework that you
| will
| > only accept incoming UDP packets from the designated host/port couple
when
| > later calling UdpClient.Receive.
| > The strange thing is the first argument to your Connect method. The
| > GetHostByName method requires a single argument and your code should not
| > compile like this. I assume this is a typo and you are actually invoking
| the
| > Dns.GetHostName() method.
| >
| > Consequently, you are saying that you are willing to receive UDP packets
| > originating from port 514 of the same machine as the one you are
listening
| > from. Pretty useless isn't it ?
| >
| > | > > Hi
| > >
| > > I'm listening on the SysLog port (514) through UDP. The problem is
that
| I
| > am
| > > not receiving anything nut I know that i get messages on the port.
When
| I
| > > use KIWI to listen on the same port via UDP tons of messages arrive..
| What
| > > am I'm doing wrong
| > >
| > > My code looks like the following...
| > >
| > > private UdpClient udpClient;
| > >
| > > private IPEndPoint IPEnd;
| > >
| > > private void button1_Click(object sender, System.EventArgs e)
| > >
| > > {
| > >
| > > udpClient = new UdpClient( 514);
| > >
| > >
| > > udpClient.Connect(Dns.GetHostByName(), 514);
| > >
| > > IPEnd = new IPEndPoint( IPAddress.Any,0);
| > >
| > > byte[] recv = udpClient.Receive( ref IPEnd ); // <<<<< I NEVER GET
PAST
| > THIS
| > > STATEMENT - receive is waiting for ever???????
| > >
| > > MessageBox.Show( Encoding.ASCII.GetString( recv ));
| > >
| > > }
| > >
| > >
| > >
| > > REgards Morten
| > >
| > >
| >
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top