CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
perl Socket programming on windows



May 5, 2010, 8:37 AM

Post #1 of 6 (1514 views)
perl Socket programming on windows Can't Post

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.
Here is the 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();
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+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+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
ReadMode 0;

# -----------------------------------------------------------------
# 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
sleep 1;
# read the response and print
while ($s->can_read(0))
print $rtn;
print "n $commentn";


May 7, 2010, 1:04 AM

Post #2 of 6 (1489 views)
Re: [bam_usic] perl Socket programming on windows [In reply to] Can't Post

I don't know whether Windows supports AF_UNIX type sockets. Did you already try the program on Windows without modifications? If you have problems, would it be an alternative to switch to AF_INET sockets?


May 9, 2010, 9:16 AM

Post #3 of 6 (1464 views)
Re: [bam_usic] perl Socket programming on windows [In reply to] Can't Post

The AF_UNIX domain is misnamed. It can work on non-UNIX systems too.


May 10, 2010, 2:42 AM

Post #4 of 6 (1459 views)
Re: [7stud] perl Socket programming on windows [In reply to] Can't Post

It can work on non-UNIX systems too.

The crucial point here is the word can. I remember that early Windows versions didn't support it, or at least not support it well, and I didn't know how good the support is in the version which the OP is using. That's why I was reluctant to say "Just use it without changes, it will work"....


May 10, 2010, 4:12 AM

Post #5 of 6 (1458 views)
Re: [rovf] perl Socket programming on windows [In reply to] Can't Post

Thanks for your response.I am new to perl.In the documentation I found IO::Socket::UNIX is supported on windows.In the following code line I don't understand what peer stands for and I need to change peer path for widnows.I tried to look at the path /home/glucose/gsm/gsmd_sock.There is no file or port name there.
In this script I don't understand where port name is specified and what is peer and how to change it for windows i.e. what is gsmd_sock.
my $sock = new IO::Socket::UNIX (Type => SOCK_STREAM,
Peer => '/home/glucose/gsm/gsmd_sock',
I appreciate your response.


May 10, 2010, 9:24 AM

Post #6 of 6 (1455 views)
Re: [bam_usic] perl Socket programming on windows [In reply to] Can't Post

I don't understand where port name is specified

I don't have that much experience with AF_UNIX sockets either, but you don't need a port for Unix Domain sockets.

See for example
It's not specifically for Perl, but the concept is the same of course.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives