# Set UDPSocket reciever buffer size?

**URL:** <https://discourse.julialang.org/t/set-udpsocket-reciever-buffer-size/3939>\
**Category:** General Usage\
**Tags:** networking\
**Created:** [May 26, 2017, 4:04pm UTC](https://discourse.julialang.org/t/set-udpsocket-reciever-buffer-size/3939 "2017-05-26T16:04:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 27, 2017, 8:31am UTC](https://discourse.julialang.org/t/set-udpsocket-reciever-buffer-size/3939/4 "2017-05-27T08:31:13Z")

</div>

Example code:

```julia
using DataStructures

# disable SIG_INT
println("To termiate the logger, press <CTRL>+<C>!")
ccall(:jl_exit_on_sigint, Void, (Cint,), 0)

# use an array with one element for global variables, such that they can be declared as const
const terminate = [false]

# create a queue for buffering incoming messages
const q = Queue(String)

# background loop for receiving UDP messages, terminated with <ctrl> + <c>
function receiveData(server_ip)
	global terminate
	udpsock = UDPSocket()
	# setopt(udpsock, enable_broadcast=true)
	bind(udpsock, server_ip, port)
	i = 0
	try
		while true
			msg = String(copy(recv(udpsock)))
			enqueue!(q, msg)
		end
	catch my_exception
		if isa(my_exception, InterruptException)
			close(udpsock)
			terminate[1] = true
		end
	end
end

server_ip = IPv4("0.0.0.0")
@async receiveData(server_ip) # start the background task of receiving UDP packages

```

---

_[View the full topic](https://discourse.julialang.org/t/set-udpsocket-reciever-buffer-size/3939)._
