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

UDP Socket with multiple network cards

All,

I'm wondering if anyone can help me with a strange problem I'm having.
First off, here's what I'm trying to do:

I'm developing a UDP network application that should allow the end user
to choose the network interface they want to send and receive UDP
packets on. Simple enough.

If the computer has a single network card and IP address this all works
great. The application binds to the local IP address and works.

Now if we introduce multiple network cards (in my configuration, one is
an ethernet card and one is a wireless 802.11 card), I can only seem to
get one card to work. To test, I have a test client on two machines. On
the machine with two cards, I bind to card number 1 and send a UDP
packet and receive it just fine on machine 2. Now if I bind to card
number 2 and send a UDP packet to machine 2, I don't get anything on
machine number 2. Now what's even more strange, if I disable either
network card and bind to the remaining enabled card, I can receive the
UDP packet just fine on machine number 2. This rules out a network
configuration issue because both cards will work if only one is
enabled, but only one will work when they are both enabled.

What could possibly be causing this? Following is some simple code I'm
using for the test client;

private void BindSocket()
{
if(udpThread != null)
{
udpThread.Abort();
udpThread = null;
}

if(udpSocket != null)
{
udpSocket.Close();
udpSocket = null;
}

udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
udpSocket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.ReuseAddress, 1);

IPEndPoint localEP = new
IPEndPoint(IPAddress.Parse(cboAddresses.Text), (int)numPort.Value);

udpSocket.Bind(localEP);

udpThread = new Thread(new ThreadStart(this.UdpThreadProc));
udpThread.IsBackground = true;
udpThread.Start();

AddOutputText("Bound to " + cboAddresses.Text + ":" +
(int)numPort.Value);

btnSend.Enabled = true;
}

private void UdpThreadProc()
{
byte[] buffer = new byte[5000];

while(true)
{
buffer.Initialize();

EndPoint remoteEP = (EndPoint)new IPEndPoint(IPAddress.Any, 0);

udpSocket.ReceiveFrom(buffer, ref remoteEP);
AddOutputText("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

AddOutputText(((IPEndPoint)remoteEP).Address.ToStr ing() + ":" +
((IPEndPoint)remoteEP).Port);
AddOutputText("");
AddOutputText(System.Text.ASCIIEncoding.ASCII.GetS tring(buffer));

Thread.Sleep(1);
}
}

private void SendData()
{
string[] address = txtSendTo.Text.Split(':');

string host = address[0];
int port = 5060;

if(address.Length > 1)
{
port = Convert.ToInt32(address[1]);
}

IPEndPoint remoteEP = new
IPEndPoint(Dns.GetHostByName(host).AddressList[0], port);

byte[] sendData =
System.Text.ASCIIEncoding.ASCII.GetBytes(txtSendDa ta.Text);

udpSocket.SendTo(sendData, remoteEP);
AddOutputText(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
AddOutputText(remoteEP.Address.ToString() + ":" + port);
AddOutputText("");
AddOutputText(txtSendData.Text);
}

If you want the full code for the test client, let me know and I'll
Email it to you. Any help would be greatly appreciated!

Nov 2 '05 #1
0 2797

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

Similar topics

0
by: Baihao Yuan | last post by:
Hello, I have a machine, which has two network cards, network card 1 and network card 2, they are on different subnetworks. The IP address of network card 1 is 192.0.0.1, the IP address of...
2
by: Alphamacaroon | last post by:
All, Are there any known bugs with the Socket class in systems with multiple network cards? If I create a Udp Socket (non-multicast) with "new Socket(AddressFamily.InterNetwork,...
1
by: Prigozhin Roman | last post by:
I have 2 network cards in the machine and I'm running C# programm which connects to the remote FTP server via socket here is the code : clientSocket = new...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
0
by: Alphamacaroon | last post by:
All, I'm wondering if anyone can help me with a strange problem I'm having. First off, here's what I'm trying to do: I'm developing a UDP network application that should allow the end user to...
0
by: kvarga | last post by:
I have written an Windows Service application, in C#, which calls a web service periodically. This application works fine on a variety of Operating Systems including XP Pro, XP Home, Windows 2000...
2
by: Macca | last post by:
Hi, I have written an asychronous socket based on the microsoft example below :- http://msdn2.microsoft.com/en-gb/5w7b7x5f.aspx My app is connected to multiple clients which connect to the...
1
by: Rollasoc | last post by:
Hello, I have a situation with my PC, where I have three network cards installed. I have a piece of hardware sending UDP messages every now and then. I want to capture these messages. But I...
5
by: =?Utf-8?B?TWlrZSBE?= | last post by:
This is a difficult question: I need to be able to input data via hand-scanner into a web page textbox, but it needs to be done more than once. The user will scan one card after another and in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.