LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2009, 12:07 AM   #1
tnine9
Member
 
Registered: Jan 2003
Posts: 39

Rep: Reputation: 15
Sending test data from a file to port and IP


Hi all,
I'm working on testing some software, and I have a question. We have several files of binary data that we need to push through our application to test. It communicates via simple TCP sockets. Is there a way I can send this data to the socket from the command line? I tried doing something like this, but telnet never picked up the data.

Code:
telnet localhost 81 << cat inputtest1.sbd
Thanks,
Todd
 
Old 04-23-2009, 12:10 AM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Use netcat for this. (See the manpages for nc(1).)

---

edit: Here is a little example -
Code:
$ cat /etc/passwd | nc 127.0.0.1 6969
(In my case I set up a listener on tcp 6969.)

Last edited by anomie; 04-23-2009 at 12:12 AM.
 
Old 04-23-2009, 10:21 PM   #3
tnine9
Member
 
Registered: Jan 2003
Posts: 39

Original Poster
Rep: Reputation: 15
Thanks for the help, but I'm getting some wierd errors. My test message is only 28 bytes in length, but when my program receives it I have as 8192 bytes on the buffer coming from the sender. I've tried both

Code:
cat test.sbd |nc localhost 8080
and

Code:
nc localhost 8080 < test.sbd
I've noticed that it sends the data, but it doesn't disconnect from the socket after the data is sent. Is there a param I'm missing? I couldn't find anything in the man pages but I need to set the socket buffer length to match the number of bytes in the message. I know this isn't a bug in the receiver given that the production system only transmits the size of the input file then closes the socket, and the receiver has the correct buffer length.

Thanks,
Todd

Last edited by tnine9; 04-23-2009 at 10:34 PM.
 
Old 04-23-2009, 10:46 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Without knowing anything about the application you're testing, I am not sure what to suggest on that front. To troubleshoot further, you may want to capture the packets and see what is going on with the tcp conversation.

# tcpdump -i lo tcp port 8080
 
Old 04-24-2009, 12:35 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
On some kernels & bash versions, you can use /dev/tcp/<host>/<port> and /dev/tcp/<host>/<port> as a device that you can cat to or from.

See the bash info manual. Section 3.6 Redirections
 
Old 04-27-2009, 04:06 PM   #6
tnine9
Member
 
Registered: Jan 2003
Posts: 39

Original Poster
Rep: Reputation: 15
Well, both solutions work for pushing data through a socket. However I'm still experiencing the issues of an invalid length. I'm actually running OS X 10.5, so it must be an issue with it's network sockets. I've tried both cat and dd to dump the bytes onto the pipe for the network calls, but it doesn't seem to help the issue. It looks like I'm going to have to write something that disconnects after sending the bytes in the file.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rpmbuild error: File ./test-2.3.0/SOURCES/test-2.3.0.tar.gz: No such file powah Linux - Software 1 12-13-2007 03:30 PM
Com port data to file Ashrael Linux - Software 2 08-26-2007 01:35 PM
Sending and receiving data to through Serial Port kalyan.penujeevi Programming 1 08-07-2006 07:55 AM
sending data to standard out and to a text file at the same time. liguorir Linux - Software 1 08-23-2005 12:14 PM
shell script: sending data through the serial port funkymunky Programming 2 06-09-2004 11:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:57 PM.

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