Hello, I've been fooling around making a chat program for my friends and I and it works alright except for timeouts and the fact that - my main problem - I can not figure out how to get a client over the internet to connect to the server. The program works correctly over a private network using private network addresses like.. 192.168. or 10... etc. However I am not sure what I need to do for a client to connect to my computer from their computer at home. at the moment in my code I use INADDR_ANY, which Im not entirely sure the meaning of. I have also tried using my external address ( the one you find if you ask for your ip on google ), There is probably some knowlege I am lacking so any help would be greatly appreciated. Thanks!!

use v5.14; use Socket; use IO::Socket; require('server_lib.pl'); flush_system(); socket(SERVER,PF_INET,SOCK_STREAM,getprotobyname('tcp')); setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1); my $my_addr = sockaddr_in(5555,INADDR_ANY); bind(SERVER,$my_addr) or die "cant bind"; listen(SERVER,SOMAXCONN); REQUEST: while(accept(CLIENT,SERVER)){ if (my $pid = fork){ next REQUEST; } else{ #child close SERVER; my $ip = get_ip(*CLIENT); my $user_name; if(recv(CLIENT,$user_name,1024,0)){ if( user_exists($user_name) || ip_exists($ip) ){ send_to_ip($ip,"User name exists (please restart);\n"); say "Attempt to duplicate name '$user_name' from IP: $ip"; next REQUEST; } else{ cache($user_name,$ip); } my $conn_msg = "{$user_name Connected}"; say "$conn_msg: $ip"; global_send($conn_msg); while(recv(CLIENT,my $data,1024,0)){ last if !ip_exists($ip); my $msg = "[$user_name] $data"; say $msg; unless( special_command($msg) ){ global_send($msg); } } } my $disconn_msg = "{$user_name Disconnected}"; say $disconn_msg; global_send($disconn_msg); remove_user($user_name); exit; } } continue{ close(CLIENT); }

In reply to multi-client server by Rudolf

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.