LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   TCP/IP server script (https://www.linuxquestions.org/questions/linux-newbie-8/tcp-ip-server-script-712342/)

adnanm 03-17-2009 04:04 PM

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

TB0ne 03-17-2009 04:50 PM

Quote:

Originally Posted by adnanm (Post 3478659)
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?

adnanm 03-17-2009 05:04 PM

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.

TB0ne 03-17-2009 05:22 PM

Quote:

Originally Posted by adnanm (Post 3478706)
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.

JaksoDebr 03-17-2009 09:20 PM

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

chrism01 03-17-2009 10:52 PM

Try this: http://beej.us/guide/bgnet/

Bebo 03-18-2009 12:13 AM

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...


All times are GMT -5. The time now is 02:44 AM.