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

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(string ipAddress,int port)
{
IPEndPoint ep=new IPEndPoint(IPAddress.Parse(ipAddress),port);
byte[] buffer=new byte[1500];
int receivedBytes=socket.ReceiveFrom(buffer,ref ep);
byte[] packet=new byte[receivedBytes];
Array.Copy(buffer,0,packet,0,receivedBytes);
return packet;
}

Jan 17 '06 #1
1 4378
> 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(IPAddress.Parse(ipAddress),port);
EndPoint ep2 = (EndPoint)ep;
byte[] buffer=new byte[1500];
int receivedBytes=socket.ReceiveFrom(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
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...
3
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...
1
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
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
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...
0
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...
2
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...
0
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 (...
5
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...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.