473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

inetd script in python?

Jan
Hi all!

I looked around a lot, but I didn't find a solution. I have to write
an simple server application to do some jobs and return a result to a
client. I tried SocketServer and this works really fine. But I didn't
manage to get a script working that is started by inetd.

So far I read about that I could use stdin and stdout for
communication since inetd handles the socket. And I read that I could
use socket.fromfd to get a socket object to work with. But both do not
work, I tried to send just a greeting back to the client or getting
some text - nothing.

Is there any working example out there - I coudn't find one. There was
just a snippet like this:

import socket
import sys
client = socket.fromfd(sys.stdin.fileno(), socket.AF_INET,
socket.SOCK_STREAM )
while 1:
bfr = client.recv(1024)
client.send(bfr)

And a similar one with 0 instead of sys.stdin.fileno(). Only thing I
get is this error:

socket.error: (134, 'Transport endpoint is not connected')

(Same thing when using stdin/stdout - I'm trying to connect via a
telnet client on a Solaris8/sparc machine).

Any hints?
Jan
Jul 18 '05 #1
4 3718
Jan <ja********@web.de> wrote:
So far I read about that I could use stdin and stdout for
communication since inetd handles the socket. And I read that I
could use socket.fromfd to get a socket object to work with. But
both do not work, I tried to send just a greeting back to the
client or getting some text - nothing.


You should find something simple like this works - inetd is supposed
to make writing internet daemons easy!

import sys

while 1:
bfr = sys.stdin.read(1024)
sys.stdout.write(bfr)

You can then test the code on the command line by typing stuff to it
and seeing it print its output.

Beware buffering though!

--
Nick Craig-Wood
nc*@axis.demon.co.uk
Jul 18 '05 #2
Jan <ja********@web.de> wrote:
Hi all!

I looked around a lot, but I didn't find a solution. I have to write
an simple server application to do some jobs and return a result to a
client. I tried SocketServer and this works really fine. But I didn't
manage to get a script working that is started by inetd.

So far I read about that I could use stdin and stdout for
communication since inetd handles the socket. And I read that I could
use socket.fromfd to get a socket object to work with. But both do not
work, I tried to send just a greeting back to the client or getting
some text - nothing.

Is there any working example out there - I coudn't find one. There was
just a snippet like this:

import socket
import sys
client = socket.fromfd(sys.stdin.fileno(), socket.AF_INET,
socket.SOCK_STREAM )


No. inetd(8) will invoke your script, with stdin/stdout/stderr attached
to incoming connection. It will take care of all socketing. And, all
you have to do is read from stdin and write to stdout/stderr.

You can skim over
http://home.eol.ca/~parkw/index.html#httpd
for an example of inetd daemon script. It's shell script, but Python
script would go similar way.

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Linux solution for data management and processing.
Jul 18 '05 #3
In article <sl****************@irishsea.home.craig-wood.com>,
Nick Craig-Wood <nc*@axis.demon.co.uk> wrote:
Jan <ja********@web.de> wrote:
So far I read about that I could use stdin and stdout for
communication since inetd handles the socket. And I read that I
could use socket.fromfd to get a socket object to work with. But
both do not work, I tried to send just a greeting back to the
client or getting some text - nothing.


You should find something simple like this works - inetd is supposed
to make writing internet daemons easy!

import sys

while 1:
bfr = sys.stdin.read(1024)
sys.stdout.write(bfr)

You can then test the code on the command line by typing stuff to it
and seeing it print its output.

Beware buffering though!


Indeed, to the point where the code you propose would not
work when you test it the way you propose.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #4
In article <8a**************************@posting.google.com >,
ja********@web.de (Jan) wrote:
....
import socket
import sys
client = socket.fromfd(sys.stdin.fileno(), socket.AF_INET,
socket.SOCK_STREAM )
while 1:
bfr = client.recv(1024)
client.send(bfr)

And a similar one with 0 instead of sys.stdin.fileno(). Only thing I
get is this error:

socket.error: (134, 'Transport endpoint is not connected')

(Same thing when using stdin/stdout - I'm trying to connect via a
telnet client on a Solaris8/sparc machine).


That's odd - works for me on MacOS X. This is a Berkeley
UNIX platform, though, and it sounds like you may have a
system there where sockets are a layer on an AT&T STREAMS
network implementation - the `transport endpoint' thing
is my clue on that. That's one thing to look at - maybe
in that system, socket operations really aren't supported
by whatever TLI module they use with inetd. Try posix.write
and posix.read instead. They may work, while Berkeley socket
functions don't.

On the other hand, inetd is really supposed to give you a
unit 0 & 1 that support socket operations, and a platform
that fails to do that would be pretty unpopular, I would
think. I guess it would have the same effect if socket.fromfd
is not working right on your platform, so that might be
something to look into if you are in a position to do that.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Disco Plumber | last post by:
I know this will probably sound weird to many of you, but I'm currently writing an NNTP server in PHP (using MySQL as the article storage). At the moment, the server is a single client handling...
2
by: DeepBleu | last post by:
When one is using an HTML form via a web broswer, the user submits the form contents and these are passed to a CGI Python script on the web server. I need to write a client script that connects to...
0
by: Marek Kubica | last post by:
Hi! I was thinking about connecting SimpleXMLRPCServer with inetd.. but I haven't been able to replace the socket by sys.stdin and sys.stdout. Maybe socket.fromfd(sys.stdin.fileno()) could help...
6
by: Paul Winkler | last post by:
This is driving me up the wall... any help would be MUCH appreciated. I have a module that I've whittled down into a 65-line script in an attempt to isolate the cause of the problem. (Real...
2
by: Efrat Regev | last post by:
Hello, I'm a data-structures course TA trying to write a python CGI script for automatically compiling and testing students' projects. Unfortunately, I've run into some questions while writing...
3
by: Obi-Wan | last post by:
I'm trying to write a daemon in C that runs under (x)inetd that communicates over UDP. I'm trying to write a simple DNS server that returns the same IP for every query it receives. Things work...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
4
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages...
1
Banfa
by: Banfa | last post by:
Looking at man swat It has the line swat is run from inetd What is inetd?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.