W5200 Socket Api - Wiznet W5200E01-M3 User Manual

Table of Contents

Advertisement

W5200 Socket API

9.1
Function
Description
socket()
To create the SOCKET n (the n-1 th
SOCKET), use the socket() function to set
the SOCKET number, protocol, port
number, and flag.
listien()
The LISTEN step is only used during
SERVER mode. After creating the
SOCKETn, change the SOCKET to LISTEN
status so that CLIENT can connect.
connect()
The CONNECT stage is used during CLIENT
mode to connect to the SERVER.
send()
In the case of TCP protocol, the
connection between the peer is already
complete before sending data
© Copyright 2011 WIZnet Co., Inc. All rights reserved.
Table 5 W5200 Socket API
Example code
Method 1 : server mode
/* sets Protocol Number */
s = 0;
// set SOCKET 0
/* OPEN SOCKET 0 */
socket(s, Sn_MR_TCP, port, mode);
while(getSn_SR(s) != SOCK_INIT);
Method 2 : client mode
/* sets Protocol Number */
s = 0;
// set SOCKET 0
/* sets port number */
any_port = 1000;
/* OPEN SOCKET 0 */
socket(s, Sn_MR_TCP, any_port++, mode);
while(getSn_SR(s) != SOCK_INIT);
s = 0;
// set SOCKET 0
listen(s);
s = 0;
// set SOCKET 0
serverip[4] = {192, 168, 1, 2};
server(destination) IP
serverport = 0x5000;
connect(s, serverip, serverport);
/* Send data to connected peer. */
// max_size_tx_buf must be smaller than the
maximum size of the TX buffer
s = 0;
//set SOCKET 0
* data_buf[max_size_tx_buf] = (uint8 *)0x7000;
set position of data buffer
len = 1460;
send(s, (uint8 *)data_buf, len);
15
(From 0 to
7)
// set
set server(destination) port
//set length is 1460 Byte
//

Advertisement

Table of Contents
loading

Table of Contents