Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 7th, 2001, 03:03 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Question

Is anyone good with the IO::Socket module? I wrote a couple of socket scripts, one for a server, one for a client. When I try to connect from the client to the server using 'localhost' it works. When I try to connect from a different machine(the client is on a different machine and I specify the IP to connect to) it doesn't work.

Is this because of security features on the box that the server script is on?
__________________
- dsb -
Perl Guy

Reply With Quote
  #2  
Old February 9th, 2001, 09:54 AM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Wink

I guess no one here could help me out. Luckily, the PerlMonks were able to do so.
If you are interested read on.

Turns out the reason that the sockets weren't working together from different boxes/IP's was because of the security features of the boxes. I couldn't even telnet into the ports I was running with the server socket so that gave us a pretty good idea.

Also found out some good things about creating sockets efficiently. I'm posting the code in case anyone is interested. One of the key points to the server socket was to not bind the socket to a specific IP, for two reasons. One, if the IP I bind to is invalid, I'm screwed and the damn thing won't work. Two, by not binding to one specific IP, the socket will listen on all possible points of entry at the port that is assigned(you have to assign a port).

Anyway, thought that was interesting. Here's the code.
First for the Server Socket.
Code:
#!/usr/bin/perl

use IO::Socket;

$sock = new IO::Socket::INET( LocalPort => 1200,
                              Proto     => 'tcp',
                              Listen    => 10,
                              Reuse     => 1,
                              Type      => SOCK_STREAM );
die $@ unless $sock;

print "Listening for incoming connections...\n";
while ( $new_sock = $sock->accept() ) {
    $clnt = $sock->sockhost();
    print "New connection from $clnt...\n";
    while ( $buf = <$new_sock> ) {
        print $buf;
    }
    print "Client disconnected...\n";
}

close( $sock );

Now for the client socket.
Code:
#!/usr/bin/perl 

use IO::Socket;

$sock = new IO::Socket::INET( PeerAddr => 'localhost',
                              PeerPort => 1200,
                              Proto    => 'tcp' );
die "Socket could not be created: $!\n" unless $sock;

print "Input Message: ";
$msg = <STDIN>;
while ( $msg !~ m/^\n$/ ) {
    $inp = $msg;
    undef( $msg );
    print $sock "MSG: $inp";
    $sock->flush();
    print "Input Message: ";
    $msg = <STDIN>;
}

close( $sock );

Right now the client is designed to reside on the same host as the server...try 'em out if you like.

Thanks for listening.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > IO::Socket


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway