# socket programming using UDP connection

**URL:** <https://community.unix.com/t/socket-programming-using-udp-connection/290221>\
**Category:** Programming\
**Created:** [June 22, 2011, 1:05am UTC](https://community.unix.com/t/socket-programming-using-udp-connection/290221 "2011-06-22T01:05:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![naresh046](https://community.unix.com/letter_avatar/naresh046/32/6_449c533f586939b6e5f246632a46421f.png) [@naresh046](https://community.unix.com/u/naresh046)\
**Post date:** [June 22, 2011, 1:05am UTC](https://community.unix.com/t/socket-programming-using-udp-connection/290221/1 "2011-06-22T01:05:42Z")

</div>

I want to send packets through single socket() but using two different port numbers in UDP. Anybody give some idea on this.

Thanks in advance.🙂

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [June 22, 2011, 1:51am UTC](https://community.unix.com/t/socket-programming-using-udp-connection/290221/2 "2011-06-22T01:51:56Z")

</div>

Using, as it originating from two different ports? Internet protocol doesn't work that way; one socket, one port. Nothing stops you from opening two ports of course.

---

<div class="post-metadata">

**Author:** ![JohnGraham](https://community.unix.com/letter_avatar/johngraham/32/6_449c533f586939b6e5f246632a46421f.png) [@JohnGraham](https://community.unix.com/u/JohnGraham)\
**Post date:** [June 22, 2011, 2:31am UTC](https://community.unix.com/t/socket-programming-using-udp-connection/290221/3 "2011-06-22T02:31:45Z")

</div>

> [@](#):
>
> I want to send packets through single socket() but using two different port numbers in UDP. Anybody give some idea on this.

Do you mean you want to control the source and destination ports? If so, you can bind() to a local port and then either sendto() the remote port or connect() to it and and write()/send().
