When sending data using UDP, a destination port is needed to be specified.
If sending by TCP, a source port should also be specified.
Are there different ports for input and output? E.g., if I specify port 1234, can I use it for both input and output or should I use different ports for output and input?
EDIT: To clarify my question: - I send data from port X. - Someone sends data to me to port X. Are those two different ports or is the same one used?
When sending data using UDP, a destination port is needed to be specified.
Correct.
If sending by TCP, a source port should also be specified.
Incorrect. The system will allocate one for you automatically if not specified. This is the normal usage.
Are there different ports for input and output?
No. The local port you are bound to is used for both.
And all this applies to both UDP and TCP.