1

Hey. Is it possible to send a packet from a C# application without using sockets? I'd like to use WebClient or HttpWebRequest in order to send specifically formatted packets to a server. Examples I've seen tend to use UDP client. Thanks

Skoder
  • 3,983
  • 11
  • 46
  • 73

2 Answers2

1

It depends on what you mean by "Specifically Formatted". HttpWebRequest is a .Net wrapper around the HTTP protocol which is not UDP in nature, so you can not customize the packets it sends other than modifying object data like headers, etc.

Chris Kooken
  • 32,730
  • 15
  • 85
  • 123
  • I see. Does that mean that there is no other way to send a more customized packet than what HttpWebRequest provides, without using sockets? thanks – Skoder Nov 22 '10 at 15:53
  • What are you trying to do exactly? – Chris Kooken Nov 22 '10 at 15:54
  • Like for Wake on Lan? Then yes. This absolutely has to be done in Sockets... See if this example works for you... http://community.bartdesmet.net/blogs/bart/archive/2006/04/02/3858.aspx – Chris Kooken Nov 22 '10 at 15:59
  • I came across that but it uses sockets. I was just curious as to whether it could be done over HTTP, but obviously not. Thanks for the help. – Skoder Nov 22 '10 at 16:00
0

You should look at the IPEndPoint class, this is designed for sending data to an network endpoint by IP and port address. Here is a simple example, see the link for more details and a longer example with error checking.

byte[] data = new byte[1024];
string payload = "<Enter Your Payload Here>";
IPEndPoint ep = new IPEndPoint("127.0.0.1", 1234); //IP + Port

Socket remoteServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes(payload);
remoteServer.SendTo(data, data.Length, SocketFlags.None, ep);
Zachary
  • 6,522
  • 22
  • 34