Socket programming example.

Can anyone give me program examples for communicating between two machines via sockets ?
In more detail.
Machine A runs a program on socket X and machine B runs a program on socket Y.
Any data entered at program on machine A appears at machine B and vice versa.
Any language acceptable, but preferably Java.

Please note:
is confusing and I do not want to be pointed there unless it does actually work.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

did u check this. this is pretty staright forward and easy.
this is an example in java

Sockets Programming in Java: A Tutorial

Essentials of Java Programming, Part 2 (from MageLang)

Client-Server Programming with Java Sockets (lots of example code)

dryzoneAuthor Commented:
Just another stupid question.
I used to run Java programs with Jar, but it does not work on newer Linux distributions.
What is the execution command used nowadays?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

# javac -g           <- to compile
and then run with
# java Foo                       <- to run
dryzoneAuthor Commented:
Java runtime not on my system.
Which of the runtimes do you suggest.?
There are hordes and each is massive.
Any one of particular long term use?

I will look at your links.. looks promissing and will come back to you.

dryzoneAuthor Commented:
The Java exam[ples above just don't work for me. Non of the programs would run.
I would like to change the specification to classical languages that can be compiled with known compilers.
Lazarus, Kylix, Ada,  Pascal or C examples.  
without the JRE on your system, none of the java programs would run

You can find a simple client server program here

A somewhat basic tutorial on network programming here

The man pages should be more than enough to help you write your own programs
once you have an idea of what needs to be done

man socket,bind,listen,connect,accept,send,recv

you said any language acceptable, so here's perl.

#!/usr/bin/perl -w

 use IO::Socket;
 use Net::hostent;              # for OO version of gethostbyaddr
 $PORT = 9000;                  # pick something not in use

 $server = IO::Socket::INET->new( Proto     => 'tcp',
                                  LocalPort => $PORT,
                                  Listen    => SOMAXCONN,
                                  Reuse     => 1);

 die "can't setup server" unless $server;
 print "[Server $0 accepting clients]\n";

 while ($client = $server->accept()) {
   print $client ">Welcome to $0; type help for command list.\n";
   $hostinfo = gethostbyaddr($client->peeraddr);
   printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost;
   print $client ">Command? ";

   $line = <$client>;
    print $client "\n";
    printf "[%s: %s]\n", $hostinfo->name || $client->peerhost, $line;

     if ($line =~ /date|time/i)  { printf $client "%s\n", scalar localtime;}
     elsif ($line =~ /who/i )       { print  $client `who 2>&1`;   }
     else { print $client "unknown command: [$line]\n"; }

   close $client;

Here's the client program:

#!/usr/bin/perl -w

    use IO::Socket;
    unless (@ARGV > 1) { die "usage: $0 host port command..." }
    $host = shift(@ARGV);
    $port = shift(@ARGV);
    $EOL = "\015\012";
    $BLANK = $EOL x 2;
    foreach $command ( @ARGV ) {
        print "sending $command: \n";
        $remote = IO::Socket::INET->new( Proto     => "tcp",
                                         PeerAddr  => $host,
                                         PeerPort  => "$port",
        unless ($remote) { die "cannot connect to $host" }
        print $remote "$command\n";
        while ( <$remote> ) { print }
        print $remote "quit\n";
        close $remote;
        print "\n";

To test these out you'll need to first run the server, then run the client with command line args.
for example ./ localhost 9000 who date

If you have perl, but dont have some of the modules installed, use cpan.   To install moduels frm
cpan you log in as root & type:   perl -MCPAN -eshell.    That will give you a prompt, then you
just type "install module" and follow the instructions.

Note these are extremely simple examples adapted from the url above.  
dryzoneAuthor Commented:
Thanks I will look at it.

dryzoneAuthor Commented:
I did not get anything that works. This question is important to me but I am sure there must be something out there that works.
I changed the specification not to use Java. It simply never works for me.
It would be nice to have something in
ADA, Pascal (FPK), Lazarus or even assembler.
PAQed, with points refunded (300)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.