Hello Monks! I had posted recently here asking about assistance with processing multiple perl files.
After much extensive research since then, I've come across various bidirectional socket server examples but so far none of them do what I need to do.
Is there some way that I could create or incorporate something that can various methods simultaneously while handling multiple clients at the same time (considered fork but I run into problems throughout.
These are the obstacles I need to overcome:
- An arbitrary number of simultaneous connections from both directions
- All request messages send on one port and receive on a different port
- Asynchronous messages
- Communication chain consists of 3 "senders/receivers"
- Remote Web Interface (Koha - written in Perl)
- Web Interface's Remote Server (Linux server - I have the access to the file system)
- Local Windows server software (This closed-source software was supplied by a third-party)
- There are 8 different "codes" that uniquely identify the type of message being sent/received
- Socket is to use TCP SOCK_STREAM
- Listening port on server must be listening 24/7(will probably run the listener as a daemon if possible/necessary)
The workflow process I need to accomplish utilizes a SEND and RECEIVE method (our local server already has these methods established - my task is to create the other side of the connection) and follows this procedure:
- Send
- I will eventually need to turn write() and read() into loops if there is more than one request sent
- The read() function will only receive a response code telling SEND if the write() message was accepted/rejected before SEND closes.
- connect()
- write() - sends a one-line (maximum 300 character) message over the socket
- read() - receives an almost immediate response
- close()
- Receive
- socket()
- bind()
- listen()
- accept()
- read() - receives a message from the local server's SEND
- write() - responds to local server's RECEIVE
- close()
I have attempted to create a single perl file (module?) called biclient.pl as a test. Ideally, what I had pictured in my mind was something along the lines of a forked server (to handle arbitrary number of simultaneous connections) that would behave differently depending on which IP address/hostname it was coming from:
#!/usr/bin/perl -w
use strict;
use warnings;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new (
PeerHost => "X.X.X.X",
PeerPort => "9000",
LocalHost => "Y.Y.Y.Y",
LocalPort => "9001",
Listen => SOMAXCONN,
Reuse => 1
)
or die "Can't connect to socket: $!\n";
while (my $client = $socket->accept) {
my $pid = fork();
if ($client->peerhost() = X.X.X.X)
if ($pid == 0) {
handle_client($client)
}
...
}
My code fails my guess because it's trying to listen and connect a peer. Any help would be very much appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.