codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  need to convert sockets in perl on linux to work on windows  BAM_USIC at 15:51 on Wednesday, May 05, 2010
 

I have a perl script for unix which uses a socket to read data from gsm modem connected to com port.I need to convert it to windows.I think most of the script is going to be same except the line which establishes the socket connection.
Could someone please help me to know which lines I should change so that it will work on windows.
I think I need to change this
# Open the socket connection to GSMD
my $sock = new IO::Socket::UNIX (Type => SOCK_STREAM,
Peer => '/home/glucose/gsm/gsmd_sock',
Timeout => 60) || die "Couldn't establish socket: $!";
Here is the full script
#!/usr/bin/perl -w

# TRG: Perl script to exercise GSM card through a set of diagnostic commands
# The results from each command are sent back to the browser client
# Accesses the GSM card via gsmd socket (for sharing)

use strict;
use IO::Socket::UNIX;
use Term::ReadKey;
use IO::Select;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

# Keep Apache happy with the content
print "Content-type: text/htmlnn";

# Open the socket connection to GSMD
my $sock = new IO::Socket::UNIX (Type => SOCK_STREAM,
Peer => '/home/glucose/gsm/gsmd_sock',
Timeout => 60) || die "Couldn't establish socket: $!";
$! = 1;
my $s = IO::Select->new();
$s->add($sock);
$sock->autoflush(1);
ReadMode 4;

# Display suitable HTML headers and send a series of commands

#print "GSM Card Diagnosticsn";
sendcommand($s,$sock,"at+cerrn",'Last Error Message','');
sendcommand($s,$sock,"at+cscs="GSM"n",'Select ASCII output','');

print "GSM Card Detailsn";
sendcommand($s,$sock,"at+cgmin",'Manufacturer Indentification','');
sendcommand($s,$sock,"at+cgmmn",'Model Identification','');
sendcommand($s,$sock,"at+cgmrn",'Revision','');
sendcommand($s,$sock,"at+cgsnn",'Serial Number','');

print "Subscriber Identificationn";
sendcommand($s,$sock,"at+cimin",'International Mobile Subscriber Identity','');
sendcommand($s,$sock,"at+ccidn",'SIM card ID','');
sendcommand($s,$sock,"at+gcapn",'List of capabilities','');
sendcommand($s,$sock,"at+cnumn",'Subscriber number','');

printf "Current Statusn";
sendcommand($s,$sock,"at+cpasn",'Status','(0=ready, 1=unavailable, 2=unknowm, 3=ringing, 4=call-in-progress, 5=asleep');
sendcommand($s,$sock,"at+cfun?n",'Functions','(power,stk)');
sendcommand($s,$sock,"at+cmer?n",'Term event reporting','(mode,kpd,disp,ind,bfr)');
sendcommand($s,$sock,"at+cclk?n",'clock','(yy/mm/dd hh:mm:ss)');
sendcommand($s,$sock,"at+csqn", 'Signal Strength','(rssi,ber)');
sendcommand($s,$sock,"at+creg?n",'Network registration ','(n,stat,location,cellident) stat=1(home) ');

printf "SMSn";
sendcommand($s,$sock,"at+cnmi?n",'New Message Indication');
sendcommand($s,$sock,"at+csca?n",'Service centre address');
sendcommand($s,$sock,"at+cmgln",'List messages');

sendcommand($s,$sock,"at+cscs="HEX"n",'Hex output','');

# Close the socket connection and were done
$sock->close();
ReadMode 0;
exit;


# -----------------------------------------------------------------
# Subroutine to send a command to the diagnostic socket and print the response
sub sendcommand {
my $s = shift;
my $sock = shift;
my $cmd = shift;
my $desc = shift;
my $comment = shift;
my $rtn = '';
#print description
print "$desc ";
#send the command
$sock->syswrite($cmd);
sleep 1;
# read the response and print
while ($s->can_read(0))
{
$sock->sysread($rtn,1);
print $rtn;
}
print "n $commentn";
return;
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: huffman encoding and decoding in C++...
•  Re: How to Change user to root using ssh::expect
•  Re: Need hosted_button_id value from PayPal generated code
•  Re: need help creating mysql database for my java code
•  Re: IsDate() in JavaScript?
•  Table error????????
•  need to convert sockets in perl on linux to work on windows
•  Re: refresh parent after closing pop up window
•  Re: running a command in remote machine by using perl


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010