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@39:deeb00b81cc9, 2018-01-23 (annotated)
- Committer:
- cassyarduino
- Date:
- Tue Jan 23 15:08:43 2018 +0100
- Revision:
- 39:deeb00b81cc9
- Parent:
- 0:e3fb1267e3c3
Release: 2.0.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cassyarduino | 0:e3fb1267e3c3 | 1 | #!/usr/bin/perl |
cassyarduino | 0:e3fb1267e3c3 | 2 | #tcpserver.pl |
cassyarduino | 0:e3fb1267e3c3 | 3 | |
cassyarduino | 0:e3fb1267e3c3 | 4 | use IO::Socket::INET; |
cassyarduino | 0:e3fb1267e3c3 | 5 | |
cassyarduino | 0:e3fb1267e3c3 | 6 | # flush after every write |
cassyarduino | 0:e3fb1267e3c3 | 7 | $| = 1; |
cassyarduino | 0:e3fb1267e3c3 | 8 | |
cassyarduino | 0:e3fb1267e3c3 | 9 | my ($socket,$client_socket); |
cassyarduino | 0:e3fb1267e3c3 | 10 | my ($peeraddress,$peerport); |
cassyarduino | 0:e3fb1267e3c3 | 11 | |
cassyarduino | 0:e3fb1267e3c3 | 12 | # creating object interface of IO::Socket::INET modules which internally does |
cassyarduino | 0:e3fb1267e3c3 | 13 | # socket creation, binding and listening at the specified port address. |
cassyarduino | 0:e3fb1267e3c3 | 14 | $socket = new IO::Socket::INET ( |
cassyarduino | 0:e3fb1267e3c3 | 15 | LocalHost => '192.168.0.1', |
cassyarduino | 0:e3fb1267e3c3 | 16 | LocalPort => '5000', |
cassyarduino | 0:e3fb1267e3c3 | 17 | Proto => 'tcp', |
cassyarduino | 0:e3fb1267e3c3 | 18 | Listen => 5, |
cassyarduino | 0:e3fb1267e3c3 | 19 | Reuse => 1 |
cassyarduino | 0:e3fb1267e3c3 | 20 | ) or die "ERROR in Socket Creation : $!\n"; |
cassyarduino | 0:e3fb1267e3c3 | 21 | |
cassyarduino | 0:e3fb1267e3c3 | 22 | print "SERVER Waiting for client connection on port 5000\n"; |
cassyarduino | 0:e3fb1267e3c3 | 23 | |
cassyarduino | 0:e3fb1267e3c3 | 24 | while(1) |
cassyarduino | 0:e3fb1267e3c3 | 25 | { |
cassyarduino | 0:e3fb1267e3c3 | 26 | # waiting for new client connection. |
cassyarduino | 0:e3fb1267e3c3 | 27 | $client_socket = $socket->accept(); |
cassyarduino | 0:e3fb1267e3c3 | 28 | |
cassyarduino | 0:e3fb1267e3c3 | 29 | # get the host and port number of newly connected client. |
cassyarduino | 0:e3fb1267e3c3 | 30 | $peer_address = $client_socket->peerhost(); |
cassyarduino | 0:e3fb1267e3c3 | 31 | $peer_port = $client_socket->peerport(); |
cassyarduino | 0:e3fb1267e3c3 | 32 | |
cassyarduino | 0:e3fb1267e3c3 | 33 | print "Accepted New Client Connection From : $peer_address, $peer_port\n "; |
cassyarduino | 0:e3fb1267e3c3 | 34 | |
cassyarduino | 0:e3fb1267e3c3 | 35 | # read operation on the newly accepted client |
cassyarduino | 0:e3fb1267e3c3 | 36 | $data = <$client_socket>; |
cassyarduino | 0:e3fb1267e3c3 | 37 | # we can also read from socket through recv() in IO::Socket::INET |
cassyarduino | 0:e3fb1267e3c3 | 38 | # $client_socket->recv($data,1024); |
cassyarduino | 0:e3fb1267e3c3 | 39 | print "Received from Client : $data\n"; |
cassyarduino | 0:e3fb1267e3c3 | 40 | |
cassyarduino | 0:e3fb1267e3c3 | 41 | # write operation on the newly accepted client. |
cassyarduino | 0:e3fb1267e3c3 | 42 | $data = "DATA from Server"; |
cassyarduino | 0:e3fb1267e3c3 | 43 | print $client_socket "$data\n"; |
cassyarduino | 0:e3fb1267e3c3 | 44 | # we can also send the data through IO::Socket::INET module, |
cassyarduino | 0:e3fb1267e3c3 | 45 | # $client_socket->send($data); |
cassyarduino | 0:e3fb1267e3c3 | 46 | |
cassyarduino | 0:e3fb1267e3c3 | 47 | sleep(1); |
cassyarduino | 0:e3fb1267e3c3 | 48 | |
cassyarduino | 0:e3fb1267e3c3 | 49 | $client_socket->close(); |
cassyarduino | 0:e3fb1267e3c3 | 50 | } |
cassyarduino | 0:e3fb1267e3c3 | 51 | |
cassyarduino | 0:e3fb1267e3c3 | 52 | $socket->close(); |
cassyarduino | 0:e3fb1267e3c3 | 53 |