Reference Home

Socket

Description

For server two functions:

- openServerTCP() to set listener

- pollingAccept() to receive link request

For client only one:

- openSockTCP()

And closeSock() for both

 

As server:

Syntax

MWiFi.openServerTCP(int port)

Parameters

port : port number (>1000)

Returns

local server socket (int)(for polling using)

 

Syntax

MWiFi.pollingAccept(int serversocket)

Parameters

serversocket: socket returned by opneServer()

Returns

a socket linked with client (int)

0xFF (255) otherwise

 

As client:

Syntax

MWiFi.openSockTCP(char *remoteIP, int port)

Parameters

remoteIP: pointer to a char string (null terminated) containing remote address

Format: "n.n.n.n"

port: port number (>1000)

Returns

a socket for communication (int)

0xFF (255) otherwise (can't open link)

 

For Server and client

Syntax

MWiFi.closeSock(int socket)

Parameters

socket to close

Returns

none

Example:

#include <MWiFi.h> //library include

 

MWiFi WIFI; //instance of MWiFi

 

int ssocket;

int csocket=0xFF;

 

void setup() {
    WIFI.begin(); // startup shield
:
WIFI.ConnSetOpen("DLink-casa");

int fc=WIFI.Connect();

:

ssocket=WIFI.openServerTCP(5000);


}

void loop()

{

if (csocket==255) //don't poll if link already established

{

int s=WIFI.pollingAccept(ssocket);

if (s<255) csocket=s;

}

}

Reference Home