This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Sending UDP Packet in C#
I have some data in hex format that I would like to send to a UDP server and then get a response back from the server that contains some data. How would I go about doing this in C#?
I might add that I do not have local access to the server, I would just like to see which response I get by sending this particular data to it.
1- A Chat Application Using Asynchronous UDP sockets
2- Send UDP packet in C#
3- Testing TCP and UDP socket servers using C# and .NET
4- Receive and send data
5- UDP Send and Receive using threads in VB.NET
6- A UDP based Reliable Data Transfer Library
7- msdn microsoft
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've searched over 2 weeks for samples or anything else for my question.
Found some topics and examples but can't use them ...
Here is the problem : I have a server-client application which the server have to listen all the time and client is sending continuously Images to the server.
I've done the send-and-done which means client send 1 image to the server and server receive the image and socket will be closed .
But i want to send continuously Images to the server ...
Found this question : Can a TCP c# client receive and send continuously/consecutively without sleep?
But can't use them and samples .
I know the basic TCP Socket Programming and Basics of Thread Programming , but can't implement this .
Sorry For my bad english !
=====edit
actually a timer captured a screenshot with 1 second interval and these captured images after a process for compressing are send to server .
its continuously sending (Just Sending).
Is there any sample or something that i can use ?
Thanks .
When sending a single message on a socket, you can just send the payload and close - and the receiver just has to read until the socket reports it has closed and they'll have the message; nice and simple, but it doesn't scale to multiple messages.
You can't just use the packet layout because TCP is implemented as a stream protocol not a packet protocol; how you receive the data does not need to match (in terms of packets) how it is sent.
Thus, to send multiple messages on a TCP socket you need to implement some kind of framing mechanism. Any number of framing mechanism are available. A very simple mechanism might be to send a sequence of:
length (4 bytes, little-endian 32-bit integer)
payload ({length} bytes)
length (4 bytes, little-endian 32-bit integer)
payload ({length} bytes)
length (4 bytes, little-endian 32-bit integer)
payload ({length} bytes)
length (4 bytes, little-endian 32-bit integer)
payload ({length} bytes)
And similarly the recipient would buffer 4 bytes, interpret the length, then read that many bytes as a frame; rinse, repeat.
This question already has answers here:
Is TCP 100% reliable? [closed]
(3 answers)
How reliable is a TCP connection?
(2 answers)
How reliable is .NET TCP protocol?
(5 answers)
Closed 5 years ago.
I'm currently working with the assumption that when sending TCP data with System.Net.Sockets.Socket.Send ,I am guaranteed to get an exception if the connection drops. Is it possible to have a connection drop at the OS layer without receiving a notification/exception in the C# application on top?
I don't imagine there is such a case, in .net, but how would I go about demonstrating this to someone that is skeptical.
Actually as far as i know It is possible. Imagine you create a packet send it and it gets dropped by the way. Os should automatically retransmit when ttl timesout. It will retry few times before giving up. More advanced firewalls have one small option as I remember. Drop with or without notification. Second looks like packet was 'lost' on the way to destination. They actually receive it but let's say- sends them to null without any answer.
I do not know how exactly socket.send works but from network point of view it is possible to not get confirmation for every packet that was lost/dropped.
This question already has an answer here:
Is there a way to specify the local port to used in tcpClient?
(1 answer)
Closed 9 years ago.
First off, I don't want to do this in production! I need to test whether someone else's implementation of a protocol on top of TCP is causing issues.
I want to use a certain outbound port over and over for multiple TCP sessions. Windows normally increments the port for each new session, and I want to circumvent this for testing. How can I set the outbound port of a TcpClient?
According to another post (Is there a way to specify the local port to used in tcpClient?). You need to use the constructor overload that takes an IPEndpoint in order to specify the local port to use.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get a specific socket and close it
I want to know a way to close an existing socket connection from a different process (In Windows). I don't have handle to the socket, I only know the port number. I think I may need to write kernel level code to do this. Any references in C#, or C++?
There are many ways to do that.
One of them is to inject a dll into the target process which will wait, for a packet or an other signal, to be sent by your main process and then close the socket.
Or you could just send a packet to the already open socket that will trigger an exception and therefore the deletion of the socket but I doubt that's going to be any easier than injecting a DLL.
Or maybe you could send a FIN signal to the open socket.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there a way to send raw packet Ethernet to other host via C#? In Windows 7 if it makes difference.
Based on suggestion by Saint_pl:
I found probably better solution - similar to SharpPcap. It's Pcap.Net - .NET wrapper for WinPcap. Now I can modify my packets whatever I want.
I have some resources for you that maybe helpful. I don't try that solutions in Windows 7 but maybe it contains some good info to start.
Raw Ethernet Packet Manipulation or mirror on CodeProject
This purpose of this article is to explain how to send a raw Ethernet packet using C# on a Microsoft platform. A raw Ethernet packet is the complete Layer 2 network frame that is sent to the physical wire. Sending a frame like this allows you to manipulate the target and source MAC addresses and the Layer 3 protocol fields.
Also some info on raw sockets (just in case you interesting too):
Client (and Server) Sockets Communication take a look on whole chapter but here key parts:
C# Raw UDP Socket Program Example
C# Raw Socket Ping Program Example part A | part B
All examples
Not sending packets but maybe interesting: A Network Sniffer in C#, SharpPcap - A Packet Capture Framework for .NET
iphelper API has some low level stuff - but probably not quite as low as you want to get
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("10.25.184.11"), 4456);
server.Connect(ip);
byte[] sendData = new byte[] { 0, 8, 32, 64 };
server.Send(sendData);
//done. now let's listen for data
byte[] receiveData = new byte[1024];
int receivedDataLength = server.Receive(receiveData);
//if the response is a string message
string stringData = Encoding.ASCII.GetString(receiveData, 0, receivedDataLength);
Console.WriteLine(stringData);