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/tcpclient.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 | #tcpclient.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 | |
cassyarduino | 0:e3fb1267e3c3 | 11 | # creating object interface of IO::Socket::INET modules which internally creates |
cassyarduino | 0:e3fb1267e3c3 | 12 | # socket, binds and connects to the TCP server running on the specific port. |
cassyarduino | 0:e3fb1267e3c3 | 13 | $socket = new IO::Socket::INET ( |
cassyarduino | 0:e3fb1267e3c3 | 14 | PeerHost => '192.168.0.6', |
cassyarduino | 0:e3fb1267e3c3 | 15 | PeerPort => '1000', |
cassyarduino | 0:e3fb1267e3c3 | 16 | Proto => 'tcp', |
cassyarduino | 0:e3fb1267e3c3 | 17 | ) or die "ERROR in Socket Creation : $!\n"; |
cassyarduino | 0:e3fb1267e3c3 | 18 | |
cassyarduino | 0:e3fb1267e3c3 | 19 | print "TCP Connection Success.\n"; |
cassyarduino | 0:e3fb1267e3c3 | 20 | |
cassyarduino | 0:e3fb1267e3c3 | 21 | # write on the socket to server. |
cassyarduino | 0:e3fb1267e3c3 | 22 | $data = "DATA from Client"; |
cassyarduino | 0:e3fb1267e3c3 | 23 | print $socket "$data\n"; |
cassyarduino | 0:e3fb1267e3c3 | 24 | # we can also send the data through IO::Socket::INET module, |
cassyarduino | 0:e3fb1267e3c3 | 25 | # $socket->send($data); |
cassyarduino | 0:e3fb1267e3c3 | 26 | |
cassyarduino | 0:e3fb1267e3c3 | 27 | # read the socket data sent by server. |
cassyarduino | 0:e3fb1267e3c3 | 28 | $data = <$socket>; |
cassyarduino | 0:e3fb1267e3c3 | 29 | # we can also read from socket through recv() in IO::Socket::INET |
cassyarduino | 0:e3fb1267e3c3 | 30 | # $socket->recv($data,1024); |
cassyarduino | 0:e3fb1267e3c3 | 31 | print "Received from Server : $data\n"; |
cassyarduino | 0:e3fb1267e3c3 | 32 | |
cassyarduino | 0:e3fb1267e3c3 | 33 | sleep (10); |
cassyarduino | 0:e3fb1267e3c3 | 34 | $socket->close(); |