xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
This time, the problem I meet is about to deal with a old snippet. This snippet receive the reqeuest from com port and answer some data. this snippet written in C works very fine until the modem is broken. Considered transmit speed and expense of buying new modem, I intend to write a perl snippet as below figure:
_____ socket _____ com1 | |________________| |----| | | | |----| ----- ------com2
That is , I circutly connect com1 and com2 in this machine. The new snippet listen some tcp port and forward the data between tcp and com port. The benifit is that I don't modify the old program.
Let's see the code took about 5 mins to me(a big advantage of perl ;))
Fortunatly, I can see the data from com2. Unfortuately, the program can't tell the command from com2 at all! I suspect two points:use IO::Socket; $server = IO::Socket::INET->new(Listen => 5, LocalAddr => 'localhost', LocalPort => 10001, Proto => 'tcp'); open( PORT, "+>COM1" ) or die "Can't open COM1: $!"; binmode(PORT); while ($client = $server->accept()) { while($response = <$client>){ print PORT $response; sleep 1; while(read(PORT, $tem_response,2048)){ print $client $tem_response; } } } close($server);
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: communication between socket and serial port
by rpnoble419 (Pilgrim) on Dec 11, 2009 at 06:06 UTC | |
by xiaoyafeng (Deacon) on Dec 11, 2009 at 09:15 UTC |