473,569 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying out UDP socket, and failing.... (on Vista)

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.Addre ssFamily, SocketType.Dgra m,
ProtocolType.Ud p))
sock.SendTo(dat a, SocketFlags.Non e, to);
}
=== recieve ===
void Receiving()
{
byte[] rbuf = new byte[1 << 14];
using (Socket sock = new Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p))
while (true)
{
EndPoint rep = new IPEndPoint(IPAd dress.Any, 0);
int read = sock.ReceiveFro m(rbuf, ref rep);
Recieved(rbuf, read, rep);
}
}
void Recieved(byte[] buf, int nRead, EndPoint where)
{
Console.WriteLi ne("Recieved {0} byte(s) from {1}", nRead, where);
}

===========

Jun 27 '08 #1
3 1302
Never mind,I found it!
I should also (in the listening code)

sock.Bind(new IPEndPoint(IPAd dress.Any, aPort))
Pay attention to 'aPort' I should use the same port for target IPEndPoint
when sending data

Jun 27 '08 #2
On Tue, 17 Jun 2008 07:33:00 -0700, Lloyd Dupont <ld@galador.rem oveme.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
Jun 27 '08 #3
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.RecieveFro m()

As to why it fails silently on Vista when ran as user, it is a mystery!
"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Tue, 17 Jun 2008 07:33:00 -0700, Lloyd Dupont <ld@galador.rem oveme.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
Jun 27 '08 #4

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

Similar topics

5
1310
by: Bob | last post by:
Hi, I have some code that sets up an asynchronous server. It is working fine on my XP machines but I can't get it to work on Vista. Actually, it "works: in that it runs but when I try to connect via telnet I get nothing. I have tried opening up the port and also turned off the firewall. Neither seems to work and it won't accept...
1
2120
by: Ergates | last post by:
I'm sure I'm just being thick, but I just can't get the following to work. I have loaded an XSD file into an Oracle xmltype table (called xsd_table here). The xsd looks roughly like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="BASE_ELEMENT"> <xs:complexType> <xs:sequence> <xs:element...
0
2798
by: Valerie Hough | last post by:
My app currently runs C#, .NET v2.0 on Windows Xp/Windows Server 2003, using asynchronous socket communication. I set up my server socket: Socket s = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); IPEndPoint ep = new IPEndPoint( IPAddress.Any, 0 ); s.Bind( ep ); int port = ep.Port;
1
3618
by: ElvisRS | last post by:
Hi, I'm writing a simple udp client using sockets. My code looks like this: initServer2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); initServer2.Connect(IPAddress.Parse(Properties.Settings.Default.InitServerAddress), Properties.Settings.Default.InitServerPort);
0
1518
by: ags5406 | last post by:
Hi All - Using Visual Studio 2005 Pro... I'm going to ask a question about some code I inherited. I'm trying to learn how it works so please bear with me if my question doesn't make sense. I have a program that acts as a socket server - a middleman between a fortran dll and several client apps. Runs fine on XP. Threw it on a Vista...
0
1700
by: Nelson R. | last post by:
Greetings, I've already posted this message on aspnet.security group (think its related to security issues), but since didn't get any response, I post it here. -- I have a problem, and been around it for some days without finding a solution. I have an aspnet 1.1 application that works perfectly on Windows XP, Windows
3
2087
by: Christian Binder | last post by:
Hello, I've got an application, which I'm trying to make Vista-compatible. My problem is, there is the small four-colored UAC-Symbol on the icon of my application. This means, that my program has to be run with administrative rights. I've spent a lot of time searching the web to find out, how Windows analyzes my program to know, it can only...
2
1892
by: Martin | last post by:
I have the following code being used in several of my PHP scripts (it's in an include file). It opens a socket connection to a process that's running on the same computer that IIS/PHP is running on. The OS is Windows XPPro. This all works fine - no problems. $portnum = 1001; $address = $_SERVER; $socket = @fsockopen($address, $portnum,...
0
1564
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.