CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  • References
  • Bash Commands
  • TCP
  • UDP
  1. linux

Sending/Receiving TCP/UDP Messages in Ubuntu

Last updated 2 years ago

The server listens for messages, and the client sends messages.

The server must be started before the client, otherwise the client will not connect.

References

Good easy guide for simple TCP chat server.

I didn't have to make any firewall changes to get this to work, so don't mess with ufw. ufw can mess up existing connections like ssh.

IANA port registration list:

Wikipedia port registration list:

Bash Commands

TCP

# Server (IP = 1.2.3.4):
# Listen for TCP messages on port 5169 (machine IP = 1.2.3.4)
netcat -l -p 5169
netcat -lt -p 5169  # Equivalent
nc -l -p 5169  # Equivalent
nc -lt -p 5169  # Equivalent

# Client (any IP on network):
# Send TCP messages to port 5169 of machine 1.2.3.4 (from any IP on same network)
netcat 1.2.3.4 5169
netcat -t 1.2.3.4 5169  # Equivalent
nc 1.2.3.4 5169  # Equivalent
nc -t 1.2.3.4 5169  # Equivalent

UDP

# Server (IP = 1.2.3.4):
# Listen for UDP messages on port 5170 (machine IP = 1.2.3.4)
netcat -lu -p 5170
nc -lu -p 5170  # Equivalent

# Client (any IP on network):
# Send UDP messages to port 5170 of machine 1.2.3.4 (from any IP on same network)
netcat -u 1.2.3.4 5169
nc -u 1.2.3.4 5169  # Equivalent
How to send and receive messages with NC in Linux?
Ubuntu | Security - Firewall
How To Use Netcat to Establish and Test TCP and UDP Connections
Netcat (nc) Command with Examples
How to check if port is in use on Linux or Unix
Service Name and Transport Protocol Port Number Registry
List of TCP and UDP port numbers