LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2009, 04:04 PM   #1
adnanm
Member
 
Registered: Dec 2004
Location: Bosnia and Herzegowina
Distribution: Centos, FreeBSD
Posts: 49

Rep: Reputation: 15
TCP/IP server script


Hello,

I would like to make a TCP/IP server script, which would listen to a port number and save any data it gets.

Any ideas?
Adnan
 
Old 03-17-2009, 04:50 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,995

Rep: Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327
Quote:
Originally Posted by adnanm View Post
Hello,

I would like to make a TCP/IP server script, which would listen to a port number and save any data it gets.

Any ideas?
Adnan
Ideas for what? What to write it in? What platform? What OS? You know what you want to accomplish, what are you looking for from us?
 
Old 03-17-2009, 05:04 PM   #3
adnanm
Member
 
Registered: Dec 2004
Location: Bosnia and Herzegowina
Distribution: Centos, FreeBSD
Posts: 49

Original Poster
Rep: Reputation: 15
to make an .sh script to run under linux.
It would listen to a port, and once a connection has been established, saved the messages to a file.

sorry for not clarifying my question.
 
Old 03-17-2009, 05:22 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,995

Rep: Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327Reputation: 4327
Quote:
Originally Posted by adnanm View Post
to make an .sh script to run under linux.
It would listen to a port, and once a connection has been established, saved the messages to a file.

sorry for not clarifying my question.
No, that part was clear...you want to "make a script". What are you looking for US to tell YOU? How to write it? What to write it in? A shell script isn't what you'd want to do TCP/IP socket programming with as a rule. C/Perl/Ruby are better choices.

But since you don't say what OS or platform you want to use, what kind of data over what port to listen to, or give any details other than you want to "make a script", not sure what else to tell you.
 
Old 03-17-2009, 09:20 PM   #5
JaksoDebr
Member
 
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
You should Google for sample code. Wrox Publishing has a very good book about Linux programming, and they have a very simple client-server development code - they usually have sample code available for download.

You will certainly need some compiled program to act as the server, coded in C/C++ or something similar. I don't doubt that creating a server as a bash script is possible, but it's certainly an awful lot of work and full of ugly hacks, just to do something that is quite easy to do in C/C++.

JD

Linux Archive

Last edited by JaksoDebr; 04-02-2009 at 05:15 AM.
 
Old 03-17-2009, 10:52 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
Try this: http://beej.us/guide/bgnet/
 
Old 03-18-2009, 12:13 AM   #7
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 31
You can always take a look at netcat, and do something like
Code:
#!/bin/bash

while true ; do
    netcat -l -p 5555 >> stuff.log
done
Connect to port 5555 (with netcat or telnet or whatever) and write some stuff and it will end up in stuff.log. The loop is necessary since netcat will exit once the client disconnects. This will also only allow one connection at any time, so it's kind of limited...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Script listening on TCP port pcmilhouse Linux - Networking 2 10-24-2006 12:15 PM
Tcp server for game dmail Programming 1 12-31-2005 08:59 PM
How do I tell an NFS server to use TCP? BrianK Linux - Networking 7 12-03-2004 05:24 PM
Tcp/ip Client Server Problem tushar123 Programming 2 03-31-2004 05:16 PM
TCP/IP server maxgor Programming 4 02-18-2003 02:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration