TCP IO::Socket::INET Listen w/o using ->accept? (1 to 1)

E

Eckstein C.

I want to know if it's possible to have a listening TCP socket (I'm
using IO::Socket::INET), that only expects one client, to instead of
using

my $client = $listen_sock->accept();

and

$client->recv($data, 1024);

as you would normally do, and instead, just do a

$listen_sock->recv($data, 1024)

on the listening socket?

This works for UDP (I know I know, UDP is connectionless) and I've bene
able to do things this way in other langs before, that let you either go
the "accept/client" route or "read from socket", 1:1 listen setup.

So basically I just want a simple 1:1 setup.

Thank you.
 
A

A. Sinan Unur

I want to know if it's possible to have a listening TCP socket (I'm
using IO::Socket::INET), that only expects one client,

If you are using TCP, a connection-oriented protocol, a connection must
be established using accept before you can receive data. This sounds so
self-evident to me that I am having difficulty understanding why this is
puzzling you.

If you want to serve only one client, then you can use the peeraddr
method to check if it is the client you expected.

This would still allow a denial of service attack to be launched against
the server. So, I would set up a firewall to only allow connections from
a given host to the service.
I've bene able to do things this way in other langs before,
that let you either go the "accept/client" route or
"read from socket", 1:1 listen setup.

So basically I just want a simple 1:1 setup.

I am not sure what "a simple 1:1 setup" is. I would definitely be
interested in knowing how one would receive data over a connection
without setting up a connection (as my expertise in TCP/IP is even less
than my expertise in Perl).

Sinan
 
X

xhoster

Eckstein C. said:
I want to know if it's possible to have a listening TCP socket (I'm
using IO::Socket::INET), that only expects one client, to instead of
using

my $client = $listen_sock->accept();

and

$client->recv($data, 1024);

as you would normally do, and instead, just do a

$listen_sock->recv($data, 1024)


$listen_sock->accept()->recv($data,1024);



on the listening socket?

This works for UDP (I know I know, UDP is connectionless) and I've bene
able to do things this way in other langs before, that let you either go
the "accept/client" route or "read from socket", 1:1 listen setup.

So basically I just want a simple 1:1 setup.

If those extra 10 characters are too offensive to you, it should be fairly
easy to define your own module which hides them behind a method call.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top