Im working on a simple im client/server. Right now its just a client that connects to a server, and the server sends the client some version info.

Here is the client:
#!/usr/bin/perl ################## #name: slut #by: jasper ################## use Class::Struct; use Time::localtime; use IO::Socket; use strict; ##################### #client configuration my $server = "localhost"; my $port = 7809; my $nick = shift || "slut"; struct( slut => [ server => '$', port => '$', nick => '$', usr_crypto => '%', #stores remote nick (key) and session encry +ption key (value) bytes_o => '$', bytes_i => '$', sock => '$' ]); print "+ - -\n* Slut v0.1a\n* By: Jasper\n+ - -\n\n"; my $sock = IO::Socket::INET->new (PeerAddr => $server, PeerPort => $port, Proto => "tcp", Reuse => 1)or die "Can't Connect to $s +erver!\n"; my $slut = slut->new(server => $server, port => $port, nick => $nick, sock => $sock); my $buff; print $sock "hey!"; while ($sock->recv($buff,256)) { chomp($buff); print "$buff\n"; $slut->bytes_i =+ length($buff); #$slut->bytes_o =+ length($data); }


Here is the server:
#!/usr/bin/perl ################## # SlutServ v1.0 # by: jasper ################## use Class::Struct; use Time::localtime; use IO::Socket; use IO::select; use strict; use Constant DEBUG => 1; ##################### #server configuration my $name = "SlutServ"; #name of server my $port = shift || 7809; #listening port my $max_conn = 15; #maximum number of connections allowed struct( slut => [ name => '$', port => '$', users => '%', #stores remote nicks and their ip addresses usr_crypto => '%', #stores remote nick (key) and session encry +ption key (value) bytes_o => '$', bytes_i => '$', sock => '$' ]); print "+ - -\n* SlutServ v0.1a\n* By: Jasper\n+ - -\n\n"; my $listen = IO::Socket::INET->new ( LocalPort => $port, listen => $max_conn, Proto => "tcp", Reuse => 1) or die "Can't Start Server + on Port $port!\n"; print "Socket Initialized!\n" if DEBUG; my $slut = slut->new(name => $name, port => $port, sock => $listen); my $reader = IO::Select->new($listen) or die "Can't create i/o select +read object!"; print "Before while loop\n" if DEBUG; while (1) { print "Start While Loop\n" if DEBUG; if (my @ready = $reader->can_read(1)) { print "Just got @ready. moving to foreach loop\n"; foreach my $handle (@ready) { print "In socket foreach loop\n"; if($handle == $listen) { print "handle is \$listen\n" if DEBUG; my $connect = $listen->accept(); print "Accepted Connection!\n" if DEBUG; syswrite($connect,"200 SlutServ v0.1a"); } else { print "Isnt \$listen\n"; } } } else { print "Not Ready!\n"; } }


The slut structure is going to be used later on. This is my first client/server pair, so I dont know if im doing everything right.

I want the server to listen for connections, accept the connections, receive data sent from the various clients, process the data sent from the various clients, and send data back out accordingly.
Any help will be appreciated

-jasper-

In reply to Client/Server by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.