# UDP Socket

**URL:** <https://forum.xojo.com/t/udp-socket/24196>\
**Category:** General\
**Created:** [May 12, 2015, 3:35am UTC](https://forum.xojo.com/t/udp-socket/24196 "2015-05-12T03:35:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manikandan\_Karuppaiah1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@Manikandan\_Karuppaiah1](https://forum.xojo.com/u/Manikandan_Karuppaiah1)\
**Post date:** [May 12, 2015, 3:35am UTC](https://forum.xojo.com/t/udp-socket/24196/1 "2015-05-12T03:35:59Z")

</div>

Hi ,  
Am new to XOJO…  
Could u please help me out for below issue?

I have created the project using the UDP socket. , my scope of the project is server need to receive the message from one port and send reply message to the same port. (i have used the Same IP address )

my code is

Dim d As DataGram  
Dim reply As string

d = UDPSocket1.Read

AddMessage("Received message: " + d.Data)

reply = "You said " + d.Data  
AddMessage("Sending to " + d.address + ": " + reply)

application only received the message from the port, but not allow to send reply message to same port.

Help me out from this…

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 12, 2015, 5:37am UTC](https://forum.xojo.com/t/udp-socket/24196/2 "2015-05-12T05:37:05Z")

</div>

[quote=186509:@Manikandan Karuppaiah]Hi ,  
Am new to XOJO…  
Could u please help me out for below issue?

I have created the project using the UDP socket. , my scope of the project is server need to receive the message from one port and send reply message to the same port. (i have used the Same IP address )

my code is

Dim d As DataGram  
Dim reply As string

d = UDPSocket1.Read

AddMessage("Received message: " + d.Data)

reply = "You said " + d.Data  
AddMessage("Sending to " + d.address + ": " + reply)

application only received the message from the port, but not allow to send reply message to same port.

Help me out from this…[/quote]

You should have a look at the UDPExample.xojo\_binary\_project in the Example projects/Communication/Internet folder.

---

<div class="post-metadata">

**Author:** ![Manikandan\_Karuppaiah1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@Manikandan\_Karuppaiah1](https://forum.xojo.com/u/Manikandan_Karuppaiah1)\
**Post date:** [May 12, 2015, 7:28am UTC](https://forum.xojo.com/t/udp-socket/24196/3 "2015-05-12T07:28:12Z")

</div>

Thanks for response;

Based on the UDP examples only i have developed the above mentioned code… In this application allows only received the message from the port, but not allow to send reply message to same port.

---

<div class="post-metadata">

**Author:** ![John\_Hansen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@John\_Hansen](https://forum.xojo.com/u/John_Hansen)\
**Post date:** [May 12, 2015, 8:47am UTC](https://forum.xojo.com/t/udp-socket/24196/4 "2015-05-12T08:47:40Z")

</div>

[quote=186541:@Manikandan Karuppaiah]Thanks for response;

Based on the UDP examples only i have developed the above mentioned code… In this application allows only received the message from the port, but not allow to send reply message to same port.[/quote]

What port are you trying to use… By default from client to server you never use same port… Client always connect above port 1024 to a listener port… Also if you go below port 1024 you will need root / administrator privilege… See [http://en.wikipedia.org/wiki/Port\_(computer\_networking)](http://en.wikipedia.org/wiki/Port_%28computer_networking%29)

---

<div class="post-metadata">

**Author:** ![John\_Hansen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@John\_Hansen](https://forum.xojo.com/u/John_Hansen)\
**Post date:** [May 12, 2015, 8:53am UTC](https://forum.xojo.com/t/udp-socket/24196/5 "2015-05-12T08:53:51Z")

</div>

Maybe this link can help you: [http://ljensen.com/rb/sockets\_readme\_framed.htm](http://ljensen.com/rb/sockets_readme_framed.htm)

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 12, 2015, 5:48pm UTC](https://forum.xojo.com/t/udp-socket/24196/6 "2015-05-12T17:48:09Z")

</div>

> [@186552:@John Hansen](#):
>
> What port are you trying to use… By default from client to server you never use same port… Client always connect above port 1024 to a listener port.

This is not true of UDP in general. However, if both apps are running on the same machine, then only one can listen to the port at a time. If the apps are on different machines, then using the same port should work just fine. We need more information about your setup and the error(s) you are getting.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 12, 2015, 5:56pm UTC](https://forum.xojo.com/t/udp-socket/24196/7 "2015-05-12T17:56:44Z")

</div>

> [@186688:@Tim Hare](#):
>
> This is not true of UDP in general. However, if both apps are running on the same machine, then only one can listen to the port at a time. If the apps are on different machines, then using the same port should work just fine. We need more information about your setup and the error(s) you are getting.

What I don’t get is that apparently the OP has modified the example project from Xojo, which works perfectly here. What did he change that broke it ?

---

<div class="post-metadata">

**Author:** ![John\_Hansen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@John\_Hansen](https://forum.xojo.com/u/John_Hansen)\
**Post date:** [May 13, 2015, 9:02am UTC](https://forum.xojo.com/t/udp-socket/24196/8 "2015-05-13T09:02:20Z")

</div>

> [@186688:@Tim Hare](#):
>
> This is not true of UDP in general. However, if both apps are running on the same machine, then only one can listen to the port at a time. If the apps are on different machines, then using the same port should work just fine. We need more information about your setup and the error(s) you are getting.

I am very curious to know where do you use same source and destination port to talk to each other… Most of the time I have only seen the client source port higher than 1023 (randomly picked) connect to a listener port

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 13, 2015, 9:14am UTC](https://forum.xojo.com/t/udp-socket/24196/9 "2015-05-13T09:14:21Z")

</div>

With UDP, there is no source port, only a destination. So it is perfectly acceptable, necessary even, for all the clients to listen on the same port. TCP has the concept of source and destination, but not UDP.

---

<div class="post-metadata">

**Author:** ![John\_Hansen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/b4bc9f/32.png) [@John\_Hansen](https://forum.xojo.com/u/John_Hansen)\
**Post date:** [May 13, 2015, 9:44am UTC](https://forum.xojo.com/t/udp-socket/24196/10 "2015-05-13T09:44:12Z")

</div>

> [@186821:@Tim Hare](#):
>
> With UDP, there is no source port, only a destination. So it is perfectly acceptable, necessary even, for all the clients to listen on the same port. TCP has the concept of source and destination, but not UDP.

I see what you mean… according to rfc 768 [https://tools.ietf.org/html/rfc768](https://tools.ietf.org/html/rfc768) source port is optional in the User Datagram header

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:45pm UTC](https://forum.xojo.com/t/udp-socket/24196/11 "2020-10-29T17:45:07Z")

</div>


