LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-14-2012, 06:05 AM   #1
malcmcmul
LQ Newbie
 
Registered: May 2012
Location: Liverpool, UK.
Distribution: OS X, RHEL, Fedora and Ubuntu.
Posts: 10

Rep: Reputation: Disabled
Open and use a port for data streaming.


Assume that I'd like to test the performance between two servers (S1 and S2) by sending multiple gigs worth of files via the DD command and a configured file share. Now, I'm trying to mimic this with streaming data via ports.
  1. The firewall on S1 and S2 have been configured to accept all connections from port 1x.
  2. What else is required to fully open port 1x?
  3. Are there any commands available to create a random bunch of data (much like dd) to pass to this port?
  4. How do I go about monitoring the port at the other side - a daemon - to then, say, convert this stream into an ever-growing file e.g. 1x-output.txt?
 
Old 05-14-2012, 06:23 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
2) Something needs to be listening for connections/data.
3) the (u)random device..
4) This can be done fairly easily with netcat.

Listenning side:
Code:
nc -l 1234 -v
x��8�]���<i������=\�~/́h�RQ%��}i��5���ɮ4B�J��{H�\	\g������E�sLB|o�b
�5$�0�ƿ3�6\z�F���ʂ�o���N'��4R�7�芧�&��F��������_;�~W�Ҷ�ɐ1J�4'�ڭ�e,XAW�,����B<��R���C<�=��Ӷ�\��.�eOV�:`lm�;��r��;�*��ͤȱ
{b���ye���;����?=�ĺ�qL��4f�RiA4��Z��OI*��C?x�7�H�P��F�]sC��E	b�m���*fA��ď�_�Q���="���dwh����k�j'@�TF�I��ώ�!�h	U�g��-�]��Nj�����E�e��s����[I;c62;9;c^C���z�A��kU��)�cޮ�.#=�#�Y���5�0��U�� ���f4�?�62;9;c62;9;c62;9;c62;9
The gibberish here, is what is being sent from the command below.
You can use normal BASH redirection to output the data to a file.

Sending side:
Code:
dd if=/dev/urandom | nc localhost 1234
See http://www.manpagez.com/man/1/nc/ for more info on using nc.
 
1 members found this post helpful.
Old 05-14-2012, 06:38 AM   #3
malcmcmul
LQ Newbie
 
Registered: May 2012
Location: Liverpool, UK.
Distribution: OS X, RHEL, Fedora and Ubuntu.
Posts: 10

Original Poster
Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by fukawi1 View Post
2) Something needs to be listening for connections/data.
3) the (u)random device..
4) This can be done fairly easily with netcat.

Listenning side:
Code:
nc -l 1234 -v
x��8�]���<i������=\�~/́h�RQ%��}i��5���ɮ4B�J��{H�\	\g������E�sLB|o�b
�5$�0�ƿ3�6\z�F���ʂ�o���N'��4R�7�芧�&��F��������_;�~W�Ҷ�ɐ1J�4'�ڭ�e,XAW�,����B<��R���C<�=��Ӷ�\��.�eOV�:`lm�;��r��;�*��ͤȱ
{b���ye���;����?=�ĺ�qL��4f�RiA4��Z��OI*��C?x�7�H�P��F�]sC��E	b�m���*fA��ď�_�Q���="���dwh����k�j'@�TF�I��ώ�!�h	U�g��-�]��Nj�����E�e��s����[I;c62;9;c^C���z�A��kU��)�cޮ�.#=�#�Y���5�0��U�� ���f4�?�62;9;c62;9;c62;9;c62;9
The gibberish here, is what is being sent from the command below.
You can use normal BASH redirection to output the data to a file.

Sending side:
Code:
dd if=/dev/urandom | nc localhost 1234
See http://www.manpagez.com/man/1/nc/ for more info on using nc.
Thanks for the response, you've provided an excellent answer!

With regards to [2], the fact we're using netcat to send the files at source and then using netcat to receive the files and redirect to a file, this has in respect set up the "Something [that] needs to be listening for connections/data. ", correct? Or is there an additional initialisation process we still haven't done? I was expecting to set up a daemon or does the "nc -l 1234 -v" accomplish this?

I've used the dd command in the past. Obviously if the file size needed to be limited, you'd just add 'bs=[size] count=1', right ?

Last edited by malcmcmul; 05-14-2012 at 06:45 AM.
 
Old 05-14-2012, 06:51 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
With regards to [2], the fact we're using netcat to send the files at source and then using netcat to receive the files and redirect to a file, this has in respect set up the "Something [that] needs to be listening for connections/data. ", correct?
This is correct, nc is the listener.
You can see this using "netstat -tnlp".
Code:
~ $ netstat -tnlp 
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:28764               0.0.0.0:*                   LISTEN      16600/skype         
tcp        0      0 0.0.0.0:45001               0.0.0.0:*                   LISTEN      22636/transmission- 
~ $ nc -l 1234 -v &
[1] 3197
~ $ netstat -tnlp
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:28764               0.0.0.0:*                   LISTEN      16600/skype         
tcp        0      0 0.0.0.0:45001               0.0.0.0:*                   LISTEN      22636/transmission- 
tcp        0      0 0.0.0.0:1234                0.0.0.0:*                   LISTEN      3197/nc             
~ $
(I have cut out some irrelevant crap from this example, but the important bits are still there)
 
1 members found this post helpful.
Old 05-15-2012, 08:26 AM   #5
malcmcmul
LQ Newbie
 
Registered: May 2012
Location: Liverpool, UK.
Distribution: OS X, RHEL, Fedora and Ubuntu.
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fukawi1 View Post
This is correct, nc is the listener.
You can see this using "netstat -tnlp".

(I have cut out some irrelevant crap from this example, but the important bits are still there)
Excellent, thanks for that. I've been doing a little bit of a testing with this and noticed it stops listening for the file once a stream stops. Is there any reason for this - I can't logically understand how it would even know a data stream has stopped unless it's keeping a timer once it starts receiving data (unless the file being sent states it's the end of the file and the listening process sees this as a stop?)? Is there a way to force it to continually listen (and output to file) until told to stop? At present I'll pass through a 1MB or 1GB file and once this ends, the listening ends. I'd like to periodically pass through data without closing the connection at the destination side.

Hopefully that question made sense. I'll gladly clarify further...

Last edited by malcmcmul; 05-15-2012 at 08:29 AM.
 
Old 05-16-2012, 04:07 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Quote:
(unless the file being sent states it's the end of the file and the listening process sees this as a stop?)?
As I understand it, this is pretty much the case, except that rather than the server (listener) detecting the end of the stream, the

Quote:
Is there a way to force it to continually listen (and output to file) until told to stop?
Yes, with the "-k" option. I would suggest reading the man pages for detailed info on using nc. I don't believe you can tell it to stop from the client (sending) side with nc itself, you would have to terminate the process manually (ctrl+c, or ssh the server(listener) and kill the process).

That said, nc wont be able to distinguish the end of one stream from the beginning of the next, as far as redirecting to a file goes..

For transferring files though, scp may be a better option, (encryption, error checking, blah blah).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
the get data from serial port function read() blocks when data not available DEF. Programming 3 11-17-2014 07:11 AM
LXer: White House to open source Data.gov as open government data platform LXer Syndicated Linux News 0 12-06-2011 05:40 AM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 06:10 AM
LXer: Open Data, Open Society: a research project about openness of public data in EU LXer Syndicated Linux News 0 06-02-2010 12:30 PM
Data streaming Lucent driver problem vblecic Linux - Hardware 1 02-25-2005 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration