Testing TCP / UDP clients and servers with a Linux platform

Sometimes you need a quick method or mechanism to test either a TCP or UDP client or server works, this can be done with the Linux netcat application. Some examples of this application usage are :-

Show Plain Text
Text code
  1. netcat -ul -p3500

This will listen for UDP packets on port 3500 of the Linux machine i.e. server.

Show Plain Text
Text code
  1. netcat -u localhost 3500

This will act as a UDP client on port 3500. On both the client and server you can type text messages and hit to transmit the text to the server or client. The +C combination will allow you to quit either the server or client.

Show Plain Text
Text code
  1. netcat -l -p 3500

This will listen for TCP packets on port 3500 as a server process.

Show Plain Text
Text code
  1. netcat localhost 3500

This will act as a TCP client on port 3500. You could also use the telnet command.

Its also quite useful to figure out what processes are on your TCP or UDP ports. The netstat application is great for this.

Show Plain Text
Text code
  1. netstat -ntpl

This will list all of your TCP ports that are open.

Show Plain Text
Text code
  1. netstat -nupl

This will list all of your UDP ports that are open.

To send a test UDP packet to a server you can use :-

Show Plain Text
Text code
  1. echo -n "foo" | nc -u -w1 localhost 3500
Filed under: Linux  Tags: Debian, Ubuntu

0 Responses to “Testing TCP / UDP clients and servers with a Linux platform”

Sorry, comments have been closed for this post.
(default) 12 queries took 4 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`220
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`220
6DESCRIBE `categories_posts`221
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'testing-tcp-udp-clients-and-servers-with-a-linux-platform' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (101) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 101 AND `PostsTag`.`tag_id` = `Tag`.`id`) 220
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 101 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount_rss` = Post.hitcount_rss + 1 WHERE `Post`.`id` = 10110
12UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 10110