473,322 Members | 1,719 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,322 software developers and data experts.

UdpClient.Receive never receives anything????

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
Nov 15 '05 #1
4 15942
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" <mo*@oticon.dk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2
>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" <ji**********@hotmail.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl... 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" <mo*@oticon.dk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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


Nov 15 '05 #3
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);

}

}



"Morten Overgaard" <mo*@oticon.dk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #4

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" <mo*@oticon.dk>
| References: <OR**************@tk2msftngp13.phx.gbl>
<OC**************@TK2MSFTNGP12.phx.gbl>
| 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: <#R*************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 213.129.10.164
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.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
|
| "Jip from Paris" <ji**********@hotmail.com> wrote in message
| news:OC**************@TK2MSFTNGP12.phx.gbl...
| > 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" <mo*@oticon.dk> wrote in message
| > news:OR**************@tk2msftngp13.phx.gbl...
| > > 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
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #5

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

Similar topics

2
by: Richy Rich | last post by:
Hi, I've developed an application in C# which spawns a thread to receive datagrams. If I use the socket receive method, there are no problems when using the application under NT or XP. I...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
0
by: Steve | last post by:
I am looking into UdpClient sample code from MSDN where one UdpClient object used for both send and receive operation. Please take a look at the link below...
2
by: Emilio | last post by:
Question about UdpClient sample ' This constructor arbitrarily assigns the local port number. Dim udpClient As New UdpClient() Try udpClient.Connect("www.contoso.com", 11000) ' Sends a...
1
by: Plem | last post by:
Hi All, I've allready posted this on the C# group (oops). I'm trying to get a UDPclient to receive. I use the sample code provided in HELP but to nbo avail. When the receive method is...
3
by: D. André Dhondt | last post by:
In VB.NET 2003, is there a way to create a System.Net.Sockets.UDPClient to listen to any address AND any port? I can get it to listen to any address, but only if I specify a port (for example,...
6
by: swartzbill2000 | last post by:
If I do this: Dim receiver As New UdpClient() Then the documentation says the system will pick a port. How can I extract the chosen port number from receiver? Bill
0
by: Johan | last post by:
Suppose: There are two devices on my network that both broadcast UDP datagrams (and they both use the same portnumber 1234). I want to create two executables that use UdpClient internally. Each...
0
by: =?Utf-8?B?VG9tbXkgTG9uZw==?= | last post by:
Ok, I'm not all that great with VB.Net, I admit that early on. Used to get on well with VB6 but we can't all live in the past I'm told. :) Basically, the following is a sample procedure, which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.