UIPEthernet library for Arduino IDE, Eclipse with arduino plugin and MBED/SMeshStudio (AVR,STM32F,ESP8266,Intel ARC32,Nordic nRF51,Teensy boards,Realtek Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet W5100 Ethernet library API. Compiled and tested on Nucleo-F302R8. Master repository is: https://github.com/UIPEthernet/UIPEthernet/

tests/perl/tcpserver.pl

Committer:
cassyarduino
Date:
2016-12-21
Revision:
0:e3fb1267e3c3

File content as of revision 0:e3fb1267e3c3:

#!/usr/bin/perl
#tcpserver.pl

use IO::Socket::INET;

# flush after every write
$| = 1;

my ($socket,$client_socket);
my ($peeraddress,$peerport);

# creating object interface of IO::Socket::INET modules which internally does
# socket creation, binding and listening at the specified port address.
$socket = new IO::Socket::INET (
LocalHost => '192.168.0.1',
LocalPort => '5000',
Proto => 'tcp',
Listen => 5,
Reuse => 1
) or die "ERROR in Socket Creation : $!\n";

print "SERVER Waiting for client connection on port 5000\n";

while(1)
{
	# waiting for new client connection.
	$client_socket = $socket->accept();
	
	# get the host and port number of newly connected client.
	$peer_address = $client_socket->peerhost();
	$peer_port = $client_socket->peerport();
	
	print "Accepted New Client Connection From : $peer_address, $peer_port\n ";
	
	# read operation on the newly accepted client
	$data = <$client_socket>;
	# we can also read from socket through recv()  in IO::Socket::INET
	# $client_socket->recv($data,1024);
	print "Received from Client : $data\n";
	
	# write operation on the newly accepted client.
	$data = "DATA from Server";
	print $client_socket "$data\n";
	# we can also send the data through IO::Socket::INET module,
	# $client_socket->send($data);
	
	sleep(1);
	
	$client_socket->close();
}

$socket->close();