Click here to Skip to main content
15,883,901 members
Everything / UDP

UDP

UDP

Great Reads

by Orekaria
Lightweight .Net library for UDP LAN broadcasting.
by honey the codewitch
Explore an Arduino based IoT web server and UDP multicaster for monitoring a remote water pump
by Zehaie M. Hailu
Python lends itself to the development of multi-threaded GUI and network applications.
by Huang Geng Geng
If you are looking for a tool

Latest Articles

by Mirzakhmet Syzdykov
Network programming in C++
by hemanthk119
This article describes modification of Arduino NINA firmware to wirelessly transmit I2S microphone data.
by Mark Beharrell
A queue based UDP protocol
by honey the codewitch
Explore an Arduino based IoT web server and UDP multicaster for monitoring a remote water pump

All Articles

Sort by Score

UDP 

6 Mar 2012 by Orekaria
Lightweight .Net library for UDP LAN broadcasting.
5 Nov 2020 by honey the codewitch
Explore an Arduino based IoT web server and UDP multicaster for monitoring a remote water pump
12 Apr 2013 by Manfred Rudolf Bihy
You're trying this the wrong way round. The server should have one socket (IP-adress and port) on which it accepts connections and then it will spawn a separate thread for each client that connects. If you were to do it your way you'd need either 40 IP adresses and listening on one designated...
26 Jul 2016 by Zehaie M. Hailu
Python lends itself to the development of multi-threaded GUI and network applications.
6 Feb 2011 by Espen Harlinn
You could do worse than starting out reading this book:http://www.cs.wustl.edu/~schmidt/POSA/POSA2/[^]It will not give you the answer, but it will enable you to understand how these things are usually done. Since you are writing a thesis, I would guess that you will have to understand the...
29 Sep 2012 by pasztorpisti
As far as I know right we had full raw socket support in windows beginning with win2000 and ending with WinXP SP1. From WinXP SP2 only raw UDP sockets are available and even raw UDP sockets have some extra restrictions. More about these limitations here:...
28 Mar 2013 by nv3
The main question is: Do you need to preserve context information from one to the next UPD requestion message?If not, i.e. if every UDP request contains all the information that is needed to answer it, there is no other reason to dispatch the requests to multiple threads than using the power...
15 Apr 2013 by CPallini
The other, quite obvious, approach would be creating a thread per client (well, two threads per client).The adavantage would be a somewhat simpler code.
22 Jul 2014 by nitrous_007
Please help with this problem be patient and read through to the end. I will really appreciate it!!!I am creating 4 sockets on a computer with 4 network adapters and binding each socket to 1 network adapter. Network Adapter 1 is at 192.168.100.10. Socket 1 binds to Network Adapter...
13 Nov 2021 by Mark Beharrell
A queue based UDP protocol
15 Apr 2010 by DaveAuld
Use the UDPClient class, here is the example straight from MSDN;// This constructor arbitrarily assigns the local port number.UdpClient udpClient = new UdpClient(11000); try{ udpClient.Connect("www.contoso.com", 11000); // Sends a message to the host to which you...
13 May 2010 by Chris Kolkman
What you need is a "state" class you can pass along. This state class can hold a reference to the EndPoint passed to the UdpClient. I'm not sure how well the example holds up with BeginReceive (especially with calling it again to continue listening) as I've only really used BeginReceiveFrom -...
18 Mar 2011 by Sergey Alexandrovich Kryukov
Using sleep time is pointless. In your case, you should create a thread from the very beginning (not by click) and keep it sleeping (actually, in wait state not using any CPU time until awaken) using thread synchronization primitives, like System.Threading.EventWaitHandle. More advanced use...
5 Jan 2012 by Sridhar Patnayak
Dear Abhishek ,Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking to set up end-to-end communications. Once a connection is set up user data may be sent bi-directionally over the connection. So if the network is VPN,Lan or Intranet,...
20 Feb 2013 by Jochen Arndt
This depends on how your LAN is connected to the internet. When the router that connects your LAN to the internet uses NAT (Network Address Translation), you must setup port forwarding for incoming packets on your router. This requires also that the computer on the internet knows the public...
12 May 2013 by Sergey Alexandrovich Kryukov
I think that using threads with blocking sockets instead of asynchronous API is much better. In most cases, communication is sequential in its nature and the flow of operations is logically independent from other threads. Therefore, using a separate thread for each communication channel (in case...
3 Jan 2014 by Rob Philpott
I think this line is the problem:int receivedBytesLen = clientSock.Receive(clientData);In that I think you are expecting to receive the whole data sent in this single call. It doesn't work like that (I've been caught out myself with this). This will return the data in chunks as it is...
21 Jul 2015 by User 59241
You have probably realised that you are starting to go around in circles. Wireshark uses pcap https://en.wikipedia.org/wiki/Pcap[^] which is a very low level packet sniffing API. It accesses the hardware directly and bypasses the TCP stack altogether. This makes it useful for diagnosing network...
7 Nov 2016 by Albert Holguin
Well, if you're not sure, TCP/IP should usually be your default go-to. That's because it has a lot of neat built-in overhead that's very useful, such as retransmissions and error checking, that UDP doesn't have. UDP should be used when you need high-speed transmissions where you don't mind...
4 Apr 2018 by Jochen Arndt
Your code will not work because the image data might contain the JPEG markers too (here: the FF D9 end of image marker). So you have to write a parser that gets also the segment length for all non stand alone markers. When such a segment is processed, pass all bytes of the length without...
20 Nov 2018 by Afzaal Ahmad Zeeshan
You need to attach the async callback1, that receives the data for your socket, on its behalf and then alerts you that data has been received. You cannot attach a receive function, as it might be blocking. You can argue, that, // Your receive call is useless as well, and so would be this, ...
13 May 2010 by kivanc.imer
Hello, I am trying to use connectionless async UDP listener.I need to get Remote Endpoint to use in processes and i can get remote Endpoint info with udpClient.EndReceive(ar, IP_Remote_End) command.But as you can see I am stopping the listener for a few milisecs.I lost a few packets in this...
13 May 2010 by yasser.enpc
My question is:How can I transfer a (large) file in UDP. Because I can't transfer an image lager than 50 kb with UDP. I am using C#. Please help me thanks
6 Feb 2011 by #realJSOP
You picked a programming project for your thesis, and you don't even LIKE programming? Beyond that, writing a thesis involves YOUR OWN research, not ours. research it, LEARN how to do it, and then write your thesis.
22 Jun 2011 by #realJSOP
You can use WCF to stream with the UDP protocol, and last I checked, WCF was compatible both WPF and Silverlight.
10 Jan 2012 by Richard MacCutchan
Why are you messing about with the data in this way? You receive a stream of bytes from the network so all you need to do is write that stream (whatever length you receive) to the disk. Don't try converting to a string (what does that achieve?) and don't write four bytes as an int.
5 Mar 2012 by Dave Kreskowiak
Your thread tasks are running the same checks thousands of times a second, with no code in there at all that gives up control and waits.Look at what your dequeue method is doing. It's going to continuously allocate TransactionSeqNum, grab a lock, execute another loop if there are...
29 Sep 2012 by Kuthuparakkal
Follow : A simple UDP time server and client for beginners[^]
31 Oct 2012 by Ed Nutting
Hi there,Are you disconnecting/stopping listening from the port properly? It doesn't look like you are. If you aren't, the port will look like it is already being listened after you close your program and thus when you try to run your program a second time. Since two things can't listen on...
27 Mar 2013 by ZurdoDev
I did this many years ago in VB6 but as I recall an exception was thrown if they could not contact the machine name. However, if the machine is online but your app is not listening then what I did was implement a polling situation so if I did not get a response back in a certain amount of time...
27 Mar 2013 by Jochen Arndt
This depends on the used communication. When the other side sends packets in regular intervals, you can stop sending packets when no data are received for a specific time and resume sending upon the next receive. If no data are send in regular intervals, just send them. Such packets are...
27 Mar 2013 by H.Brydon
You can set up your own handshake protocol on top of UDP. In other words, have the receiving machine send a response that the sender will process.
14 Apr 2013 by parths
I couldn't see any calls setting the socket to work in non-blocking mode. Did you take a look at ioctl[^] (optionally ioctlsocket[^] for win32) with the FIOASYNC and/or FIOBNIO[^] options?Here's the first tut link[^] I got from google. You might find better ones.I hope this...
14 Apr 2013 by pasztorpisti
You have to turn the socket into nonblocking mode even if you are using select() and its friends. On some versions of windows select() is able to wake up spuriously because the network stack receives some data but when you actually start reading the socket it can find out that the crc of the...
15 Apr 2013 by JackDingler
Your approach is reasonable. Keep the sending and receiving threads simple.Use queues to buffer the data for the clients. Create a queue for each client. You could have a pool of threads, then processing incoming packets from those queues. As CPallini mentions, you could create a...
7 May 2013 by KarstenK
i guess your threads are blocking the network api.why arent you making some outout or use your debugger...
7 May 2013 by KarstenK
Do the networking stuff in a own thread. Use PostThreadMessage to communicate with your main thread.
7 May 2013 by Jochen Arndt
Did you report errors and terminate the thread when a function call fails?There is at least one wrong call that should result in an error return (best case) or undefined behaviour (worst case):WSAWaitForMultipleEvents(2, &hEvent, FALSE, WSA_INFINITE, FALSE);You are passing 2 for the...
12 May 2013 by ayesha hassan
I had been working on a Server Client aplication where Server is going to service(sendto + receivefrom)'x' number of Clients at a time. For this purpose, I have created 'x' number of threads on Server side so that each thread is dadicated to one single client. Inside each thread there is a...
7 Feb 2014 by Mattias Högström
iAddrLen is not a length. It is a badly named variable.It is a Socket descriptor, but they use it as an indirect counter of number of sockets.A SOCKET is just an integer.Select can be used to look if one can read or write to sockets.This implementation of select has 5...
1 Apr 2015 by Richard MacCutchan
You should not use UDP for such an application, unless you include your own message checking. UDP[^] is not reliable, as messages can appear in any order and are not guaranteed to be delivered. If the data is important then you should be using TCP.
28 Apr 2015 by Pascal-78
The solution was too simple:increase the Socket Option ReCeiVe BUFfer (also named SO_RCVBUF).by default, this buffer is 8kb, in my case it is the size of one UDP packet. That's mean, when my client reads the packet it must be done before the server sends a new packet or the new packet...
2 Jul 2015 by Dave Kreskowiak
Why are you even using UDP? From what you describe, you cannot lose data.UDP doesn't guarantee the data gets to the destination and doesn't even guarantee the packets show up in the correct order!What you describe requires TCP, not UDP.UDP is used to broadcast connectionless data...
20 Jul 2015 by Sergey Alexandrovich Kryukov
From your explanation, I see no need in changing any priorities.The effect of thread (and, don't forget, also the process priority which affects combined priority of the process's thread) in Windows it totally probabilistic. At the same time, boosting the priority to the extremes, for a...
20 Jul 2015 by KarstenK
The UDP reading is important for getting input and NOT missing it, so I would use normal priority. I prefer using the THREAD_PRIORITY_BELOW_NORMAL flag for non-foreground threads. If you go to low, they wont run but wait. There is no reason for going to low and you better test it under realistic...
21 Jul 2015 by Kornfeld Eliyahu Peter
Wireshark is an open-source tool, so you can get its code and learn it to understand, how exactly the goals are fulfilled...https://www.wireshark.org/[^]
20 Feb 2016 by Maciej Los
I'd suggest to read this: Open a port in Windows Firewall - Windows Help[^]. If it won't help, you should provide more details, as Richard and Caroline have mentioned in the comments to your question.
20 May 2016 by Richard MacCutchan
You already posted this question at How do I use UDP sockets in C [LINUX][^] and received feedback. Please do not repost.
10 Apr 2017 by Jochen Arndt
Your system sends to this address: InetSocketAddress sd=new InetSocketAddress("192.168.8.101",40000); The other system sends to: InetSocketAddress sd=new InetSocketAddress("192.168.8.101",50000); Did you see it now? The other systems sends the data to himself on port 50000. You have to specify...
8 Jan 2018 by Jochen Arndt
When using localhost (loopback), there should be no packets lost and no significant delay. So the problem may be sourced by your implementation (probably the server code that handles receiving). Network receiving code should be event driven running in an own thread. Then it can react...
4 Apr 2018 by KarstenK
For sending over the network the splitting of the binary data is enough. If you want smaller jpeg than you must use higher compression or split the decompressed picture in sub pictures and than compress. The article CXImage shows these techniques.
21 Aug 2018 by Jochen Arndt
UDP is a Stateless protocol - Wikipedia[^] where you don't have any feedback. If you need some kind of acknowledgement, it has to be implemented in the top protocol. That means you have to define such a protocol or use an existing one and implement it in code. But it is usually better to use...
20 Apr 2021 by Richard MacCutchan
The main issue is that UDP messages are not guaranteed to be delivered, or delivered in the correct order. Whereas TCP message are guaranteed to be delivered and in the correct order. So if you use UDP you need to add your own message control to...
14 Jun 2021 by Greg Utas
Combining a server and client probably isn't appropriate. They should run on different threads, which should also be separated from their work and GUI threads, respectively. All of them can be in the same .exe, though. Although it may be more...
10 May 2022 by Richard MacCutchan
Study the tutorials: Lesson: All About Sockets (The Java™ Tutorials > Custom Networking)[^]
26 Sep 2022 by Death Smoke
I'm trying to make a connection between two computers both of them are using tp-link adapter , but i'm not receving anything from client . #include #include using namespace std; int main() { ...
16 Mar 2012 by Faultyboy
Hi there,I was wondering if someone wouldn't mind looking at a bit of my code and help me by pointing out what I'm doing wrong. I am trying to send and receive a multicast in the same application. When i was designing the app I got it to send and receive fine on the loopback so the bulk of...
15 Mar 2010 by ALEXZUPO
I'm looking for a simple example to put in a TextBox a packet sniffer from a UDP socket.Thanks
14 Apr 2010 by Antal Dominik
Hello everybody!I have a game server (WoW).I want my players to download my custom patches to the game.I've done a program that checks for update/downloading things.I want my program to send a packet to my game server if player have all my patches. I dont need any response from the...
19 May 2010 by eco2709
Greetings all.I have almost no experience with Network programming on C#.I have an Asynchronous UDP socket on a server that sends data to clients.If one of the client crashes i get the next Socket Error:Message = "An existing connection was forcibly closed by the remote...
19 Jul 2010 by luigi_dipalo
Hi,I've a big problem:i'm sending UDP pkt from a micro to a pc.In the pkt I send there is a counter. I send 1Kbyte pkt at 100 Hz.When I receive the pkt from the pc I lose some pkt. I see that because I increase a counter every time I receive one of them and this number is different from...
20 Jul 2010 by Sauro Viti
From User Datagram Protocol[^]):UDP uses a simple transmission model without implicit hand-shaking dialogues for guaranteeing reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without...
3 Aug 2010 by Jarno Burger
My thingies that i found out with the same probs , these are my hints :1I found out that visual studio debug can do a break in debugmode , but that i wouldnt matter so much if this would happen. cause the rest was still connected.2I placed the beginrecieve also in a try...
6 Aug 2010 by DaveInsurgent
Adding an answer here since I found this, it did not help, but eventually I worked it out.Use the BeginReceiveMessageFrom method, and before you Bind(), for good measure, set the following option:s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);This...
14 Sep 2010 by techtechtech
How to send data (through UDP) from windows to linux (UDP Send and Receive) using threads in VB.NET
14 Oct 2010 by Stevekodos
HiVB 2010 express question on socket dataI am trying to send and recieve data over ethernet on UDP, I have had some success but there is a data access niggly I just can't seem to get past and a variable definition I just don't understand.1. What I don't understand Dim...
29 Oct 2010 by eg gigo
[Byte]() : Array of bytelikedim x() as string 'Array of stringor dim x as string() '
9 Nov 2010 by David Knechtges
Not exactly certain of your questions, but I will answer given my use of the UDP protocol in my apps.I have a server and many clients on a LAN that use UDP for comms. The server broadcasts data to the clients every so often, and the clients also broadcast data to the server every so often....
20 Dec 2010 by kelavar
hello,i have program that using udp protocol with broadcasting the problem is that i want speed send data be in 21 percent of 1 GiG bandwith of my networkbut the max band with my program can use is 9 percent of 1GiG can anyone help me please ?hello,i have program that using udp protocol...
20 Dec 2010 by kelavar
hello,i have program that using udp protocol and broadcasting ,my computer have 2 nic ,how i can use synchronic two nic in my program for sending data?in windows xp or server 2003.thank you
20 Dec 2010 by Dave Kreskowiak
You cannot just command the NIC to use 205 of the available bandwidth. If you're only using 9%, you're code isn't generating enough data fast enough to utilize the network that much.
20 Dec 2010 by kelavar
hello,I have program that use receiving data in udp protocol and broadcast ,the program work good in debug mode ,but in release mode it loss data,help me. thank you
20 Dec 2010 by #realJSOP
UDP is not the protocol you want to use if you want to ensure that you get ALL of the data. You actually want to use TCP/IP.
20 Dec 2010 by kelavar
the size of packet that i send is 1472 .is it possible to send packet with size more than 1472?
25 Dec 2010 by kelavar
BOOL CUDPServerSocket::Connect(){ char psz[1024]; addrinfo local; struct addrinfo hints; BOOL Result = FALSE; try { ////************************************************************** WSAData data; WORD wVersion = MAKEWORD(2,0); int...
29 Dec 2010 by Electron Shepherd
Take a look at the TCP_NODELAY socket option, and reseach the Nagle algorithm. It might help, but it may be that the speed is due to factors outside of your program's control (QoS implemented in by the network hardware, for example)
1 Jan 2011 by kelavar
Hello,I have a program that uses UPD and broadcasting. My computer has two NICs. How can I utilize both of my NICs in my program for sending data? My system is Windows XP or Windows Server 2003.Thank you!
1 Jan 2011 by Manfred Rudolf Bihy
Sounds to me as if you wanted to send your data utilizing both network cards for a connection. Is his correct?If it is you would want to read this:Link aggregation aka Trunking[^]Configuring a system so sending uses both nics enables you to double your bandwidth.Best...
10 Jan 2011 by evildarkvirus
Hi,I have a problem, I am very bad at programming and have a UDP client to write.The client software should take the IP address and port number of the server it is talking to (poss on command line).Then: * It reads a line of text from standard input, * sends this text in a...
10 Jan 2011 by HimanshuJoshi
Read this[^] article, and look into the "Client Program" section of it. Also look at Winsock[^] for further details.
1 Feb 2011 by Indivara
You give no details of what language, etc, so this may be of no use. Take a look anyway:How to develop a SNMP extension agent DLL[^]-- update --Another oneSNMP library[^](Next time - search first, then ask!)
6 Feb 2011 by pegaz9
Hi, i am from Poland and i am not fluent English.I am writting M.A thesis. Supervisor want that i programmed protocol communication but i doesnt know how to do it. It protocol should be do/has:- used socket(UDP protocol)- consisted of package, for example: init, bye ping, message,...
21 Jun 2011 by Manfred Rudolf Bihy
First you construct a UDP socket and then try to set a TCP option. Don't you kind of think that error would have to be anticipated? Nagle Algorithm[^] is for TCP and has nothing to do with UDP. See here for the options available for UDP:...
22 Jun 2011 by Kasun Koswattha
Hi All,We are using VLC player to stream UDP streams. But We want want to achieve this in WPF and Silverlight. Is there a way to achieve this with WPF or Silverlight without using VLC. Thanks in Advance.
14 Nov 2011 by hoernchenmeister
Hello world,I am currently facing an ugly problem after our admin installed windows updates.We have a service running on a server in our local network.It registers itself on startup in a database, writing its ip and the number of a dynamically assigned port for UDP communication.Clients...
15 Nov 2011 by hoernchenmeister
Unfortunately our admin installed a virtual network adapter (Oracle Virtual Box) on all the Win 7 64bit machines together with the updates... So it wasn't obvious to spot the problem right away... Disabling the virtual network adapter did the job and everything started to work again.
5 Jan 2012 by Abhishek Nandgaonkar
heyy guys.. m implementing PEER TO PEER FILE TRANSFER..What protocol should I use? TCP or UDP? And why?
5 Jan 2012 by Abhishek Nandgaonkar
Yes, agreed. But what i want is precisely how easy or difficult is it to implement either of the options.Also, if you have an experience of making an application of similar kind, i can get a better answer.
10 Jan 2012 by GabeA
I am currently working on a program that receives UDP packets of size 1460 bytes per packet and continuously streams the bytes to the hard drive of my PC. Currently, my program can only receive and stream 84 packets before data loss occurs. I need my program to be realtime with a fast sampling...
10 Jan 2012 by CodyDaemon
I few things which should help on the speed front...Open the file and keep it open, and just write data to it as it comes in, and then close the file when the program exits. Open and closing files for each packet is just overhead which can easily removed.Why are you writing each 'int' by...
5 Mar 2012 by Sameer Alomari
Hello,I have a listener thread that listens to UDP transactions and en-queue them into _TransactionQ, I also have another thread that de-queue the transactions from _TransactionQ, it will do a lot of processing to confirm the correct order of the transactions, it also has a logic to detect...
20 Mar 2012 by Andre Trollip
Hi Guys,I'm at my wits end.I have a self hosting (console app) WCF service using Net.Tcp binding with all default settings.Inside one of the service methods, I use a UdpClient to send a udp packet to another unrelated IP/Port.When the method returns, I get that boilerplate...
21 Mar 2012 by Faultyboy
Ok I got it... :) For anyone who is interested this is the code to send and receive a UDP broadcast from the same app.. you have to specify the source port and the destination port for sending and receiving..Public EndPoint As New IPEndPoint(IPAddress.Parse("255.255.255.255"), 1001) ''Send...
14 Apr 2012 by Richard MacCutchan
Google for "C++ sockets" there are plenty of samples available.
19 May 2012 by amkom
Hi!I have a C++ class that sends UDP packets using Winsock2 (kind of a wrapper).I noticed that sending packets smaller than 1KB takes 0ms delay (measured by GetTickCount()). When the size is over 1KB the timing becomes almost 3seconds!!!Does anyone have any idea what can cause this...
15 Jul 2012 by GabeA
Hello,I am trying to write a C# code that will wait for any broadcasted udp message. This message will be an IP Address. After receiving the message, I want to parse the IP address received and then continue to receive udp packets from that IP Address. I already have working code that can...
15 Aug 2012 by T__12
You could use Socket class and its BeginReceiveFrom method to get remote EP.
29 Sep 2012 by Cyberwarfare
Hey code-project, I am wanting to ask this question, for quite sometime anyway the question: How can i create an Raw socket which sends an lot of UDP packets in c++ under Windows? If so please show me an code of how to do it or an tutorial. Thanks In advance, ...
26 Oct 2012 by wwwllg
you can look at www.goodudx.com,it can trans file with udp.udx is tcp-over-udp.