473,698 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket ReceiveFrom Problem

Does the function below returns an UDP packet, for example, from the
local machine? Why does it give me an error: "The best overloaded
method match for ReceiveFrom... has some invalid arguments". Why this
error?

How can I receive a packet from a specific adapter, for example, my
local machine? Is there a better way? This way won't work. The error is
in "ref ep"... how does receiveFrom work?

Thanks.

public byte[] ReceiveFrom(str ing ipAddress,int port)
{
IPEndPoint ep=new IPEndPoint(IPAd dress.Parse(ipA ddress),port);
byte[] buffer=new byte[1500];
int receivedBytes=s ocket.ReceiveFr om(buffer,ref ep);
byte[] packet=new byte[receivedBytes];
Array.Copy(buff er,0,packet,0,r eceivedBytes);
return packet;
}

Jan 17 '06 #1
1 4402
> Why does it give me an error: "The best overloaded
method match for ReceiveFrom... has some invalid arguments". Why this
error?


ReceiveFrom takes a ref to an EndPoint object; you're passing a ref to
an IPEndPoint, which can't be cast down to EndPoint implicitly as its
passed with ref. So, create another local, of type EndPoint, and set
this to (EndPoint)ep;, and pass it as the parameter, e.g.
IPEndPoint ep=new IPEndPoint(IPAd dress.Parse(ipA ddress),port);
EndPoint ep2 = (EndPoint)ep;
byte[] buffer=new byte[1500];
int receivedBytes=s ocket.ReceiveFr om(buffer,ref ep2);

Jan 17 '06 #2

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

Similar topics

4
2428
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to the prompt. I have to push Ctrl-C in order to have it exit completely. The GUI is closed though. This is a piece of code from the main class that connects to the server and starts a thread that handles the connection: =======================...
3
2200
by: ferbar | last post by:
Hello all, This may sound pretty basic stuff.. but I'm working on a socket example whose client seems to work fine, but the server doesn't send to the client the expected result. The problem is that I want to trace what the server socket is doing, but I'm unable to see any of my fprintf or printf stuff. Please take a look to the example:
1
2113
by: Chang | last post by:
why Socket.ReceiveFrom(byte, ref EndPoint) and SendTo(byte, ref EndPoint) uses ref ? I know what ref means but why it has to use ref is the question. Thanks a lot, Chang
4
2350
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
1
7054
by: scott | last post by:
Hi all hope some one can help me with this prob because it is really annoying me and I can't seem to solve it. Just like to say thx to any one that can offer any help. Ok the prob. I have a server which accepts new connections using the Socket.BeginAccept() function. This is done in its own thread using the following code.
0
1068
by: Ron L | last post by:
I am trying to write a program that will open a UDPClient and listen on it. I have based my code on the example at MS in the "UDPClient.Receive Method (.NET Framework)" file, but when I try to call the .Receive method I get the following exception: System.Net.Sockets.SocketException: An invalid argument was supplied at System.Net.Sockets.Socket.ReceiveFrom(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint&...
2
5693
by: Rene Sørensen | last post by:
I'm using .NET 2.0 VS 2005 I'm creating a function that dos something similar to the. SmoApplication.EnumAvailableSqlServers() function. But for som resone I get an error or do i?. The problem is that the program just return from the function when it reach the recive part( reviced = socket.Receive(bytBuffer); ), below here you can se the code. I used eathereal to check the package that is send and reviced, that looks all fine. I do...
0
1520
by: Johan | last post by:
Why is the parameter remoteEP of the function Socket.ReceiveFrom() a ref parameter and not an out parameter? http://msdn2.microsoft.com/en-us/library/wdfskwcy.aspx public int ReceiveFrom ( byte buffer, ref EndPoint remoteEP )
5
6873
by: natambu | last post by:
I have a linux box with multiple ip addresses. I want to make my python client connect from one of the ip addresses. Here is my code, no matter what valid information I put in the bind it always comes from the default ip address on the server. Am I doing something wrong? ------------- #!/usr/bin/python import socket
0
8598
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9016
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8856
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
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

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.