473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Socket Connection To Mico Controller

Hi,

I am able to open a socket connection to a micro controller, connected to a lynksys router, using visual basic code on a windows web site. Now I'm trying to open a socket connection using Perl on a linux server. I'm not having any luck at all. I'm not completely new to perl programs, but most of my experience is in simply installing and modifying freeware programs. Can anyone tell me what's wrong with this code?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. use IO::Socket; 
  3. my $sock = new IO::Socket::INET (
  4.     PeerAddr => '24.179.20.129',  #not real address
  5.     PeerPort => '59004', 
  6.     Proto => 'tcp', 
  7.     ); 
  8.  
  9. or die "Could not create socket: $!\n" unless $sock; 
  10. print $sock "R1R0"; 
  11. close($sock);
  12. print "Content-type: text/html\n\n";
  13. print "Hi there!\n";
  14. exit;
  15.  
I get an Internal Server Error

if I comment out the "or die" line and the "print $sock" line it will run without an error and print "hi there", but the socket obviously does not do anything.

What I'm trying to do is send the command R1R0 to a micro controller which in turn controls a toy robot. I'm able to do it with visual basic, but not perl.

Thanks!!!

Dwight
Mar 16 '08 #1
6 1657
numberwhun
3,509 Expert Mod 2GB
Hi,

I am able to open a socket connection to a micro controller, connected to a lynksys router, using visual basic code on a windows web site. Now I'm trying to open a socket connection using Perl on a linux server. I'm not having any luck at all. I'm not completely new to perl programs, but most of my experience is in simply installing and modifying freeware programs. Can anyone tell me what's wrong with this code?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. use IO::Socket; 
  3. my $sock = new IO::Socket::INET (
  4.     PeerAddr => '24.179.20.129',  #not real address
  5.     PeerPort => '59004', 
  6.     Proto => 'tcp', 
  7.     ); 
  8.  
  9. or die "Could not create socket: $!\n" unless $sock; 
  10. print $sock "R1R0"; 
  11. close($sock);
  12. print "Content-type: text/html\n\n";
  13. print "Hi there!\n";
  14. exit;
  15.  
I get an Internal Server Error

if I comment out the "or die" line and the "print $sock" line it will run without an error and print "hi there", but the socket obviously does not do anything.

What I'm trying to do is send the command R1R0 to a micro controller which in turn controls a toy robot. I'm able to do it with visual basic, but not perl.

Thanks!!!

Dwight
I would question whether you need the "or" before the die statement. You are saying to "die, unless this is true", so I don't think you need it.

I think the "or" is only needed if you put it at the end of something like an open.

Regards,

Jeff
Mar 16 '08 #2
Thanks Jeff. Taking the "or" out did not help. I still get a 500 Error. I can make the following "work", at least it does not return an error. It makes me think there is something wrong with my use of an IP Address in the PeerAddr line. Also, I can not find an error in the server error log.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #!/usr/local/bin/perl
  4. use IO::Socket; 
  5. my $sock = new IO::Socket::INET (
  6.     #PeerAddr => '24.179.20.999', 
  7.     #PeerPort => '59004', 
  8.     PeerAddr => 'www.shelato.com', 
  9.     PeerPort => 'http(80)', 
  10.  
  11.     Proto => 'tcp', 
  12.     ); 
  13. die "Could not create socket: $!\n" unless $sock; 
  14. print $sock "R1R0"; 
  15. close($sock);
  16. print "Content-type: text/html\n\n";
  17. print "Hi there!\n";
  18. exit;
  19.  
  20.  
  21.  
The project I'm working on can be seen at the home page in my profile. I'm able to open a winsock using VB from my laptop, and I can open a socket using VWD Experss on a windows server with ASP.net 3.5. But I really want to move my robot control panel over to a Linux server and use Perl. I'm fairly confident my receiving router and port forwarding is working since these other programs work.
Mar 16 '08 #3
numberwhun
3,509 Expert Mod 2GB
Thanks Jeff. Taking the "or" out did not help. I still get a 500 Error. I can make the following "work", at least it does not return an error. It makes me think there is something wrong with my use of an IP Address in the PeerAddr line. Also, I can not find an error in the server error log.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #!/usr/local/bin/perl
  4. use IO::Socket; 
  5. my $sock = new IO::Socket::INET (
  6.     #PeerAddr => '24.179.20.999', 
  7.     #PeerPort => '59004', 
  8.     PeerAddr => 'www.shelato.com', 
  9.     PeerPort => 'http(80)', 
  10.  
  11.     Proto => 'tcp', 
  12.     ); 
  13. die "Could not create socket: $!\n" unless $sock; 
  14. print $sock "R1R0"; 
  15. close($sock);
  16. print "Content-type: text/html\n\n";
  17. print "Hi there!\n";
  18. exit;
  19.  
  20.  
  21.  
The project I'm working on can be seen at the home page in my profile. I'm able to open a winsock using VB from my laptop, and I can open a socket using VWD Experss on a windows server with ASP.net 3.5. But I really want to move my robot control panel over to a Linux server and use Perl. I'm fairly confident my receiving router and port forwarding is working since these other programs work.
Just something I noticed, but your use statement says "use IO::Socket;", but in your "new" declaration, you are specifying "IO::Socket::INET". If you look at the page for that module, the use statement should also contain that module, including the INET piece.

So, it looks like you are specifying one module and trying to use another. I would change my use statement to be:

Expand|Select|Wrap|Line Numbers
  1. use IO::Socket::INET;
  2.  
And if it isn't already installed, then install it before executing the script. The reason I say this is IO::Socket::INET inherits all of the methods and variables from IO::Socket, but it isn't used unless you specify its use statement.

Regards,

Jeff
Mar 16 '08 #4
Hi,

Any other ideas? I know it's a little odd to be communicating over the internet with a robot. I'm not sure where else to go for help on the perl socket connection.

Thanks again,

Dwight
Mar 18 '08 #5
Just something I noticed, but your use statement says "use IO::Socket;", but in your "new" declaration, you are specifying "IO::Socket::INET". If you look at the page for that module, the use statement should also contain that module, including the INET piece.

So, it looks like you are specifying one module and trying to use another. I would change my use statement to be:

Expand|Select|Wrap|Line Numbers
  1. use IO::Socket::INET;
  2.  
And if it isn't already installed, then install it before executing the script. The reason I say this is IO::Socket::INET inherits all of the methods and variables from IO::Socket, but it isn't used unless you specify its use statement.

Regards,

Jeff
Sorry jeff, I'm reading from a bberry tonight and missed your reply, will try these changes tomorrow. Thanhs!!!
Mar 18 '08 #6
Just something I noticed, but your use statement says "use IO::Socket;", but in your "new" declaration, you are specifying "IO::Socket::INET". If you look at the page for that module, the use statement should also contain that module, including the INET piece.

So, it looks like you are specifying one module and trying to use another. I would change my use statement to be:

Expand|Select|Wrap|Line Numbers
  1. use IO::Socket::INET;
  2.  
And if it isn't already installed, then install it before executing the script. The reason I say this is IO::Socket::INET inherits all of the methods and variables from IO::Socket, but it isn't used unless you specify its use statement.

Regards,

Jeff
use the Type key as SOCK_STREAM or Listen key with que number.

may try this also:

Expand|Select|Wrap|Line Numbers
  1. use IO::Socket::INET;
  2. my $sock = new IO::Socket::INET ( '24.179.20.999:59004' );
  3.  
this will take tcp as default and SOCK_STREAM as default.
If not try to print the $@ to know the error completly.
Mar 18 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Hameed Khan | last post by:
hi all, i am getting some problems with my first socket script. can any one of you point me why this is happening. the server script suppose to accept one connection at a time and send countdown...
1
by: Volkan YAZICI | last post by:
hi all, i've been working on a communication server to talk with an io controller device. i've written a quick and dirty php script a while ago and now i need to port it to python (for a real...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
2
by: ttan | last post by:
Hi, I have 7 computers and 5 controllers(no OS) connected to Domain controller. when I used WMI to query for registry, it take a long time (about 60 minutes) to return the result. if it a...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
0
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are...
3
by: tulika dutta | last post by:
after 8 hrs my MySQL connection with JDBC gets time out. It gives the error java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.