TCP Multi-Accept Server & Sockets AT Commands

BSD Socket FunctionsSocket

  • SetSocketOpts
  • Bind
  • Listen
  • Accept
  • Send
  • Recv
  • Connect
  • Close

Connection Server Setup

 

AT Command Function
P0=<0,1,2,3> Select Socket
P1=<0,1,2,3> Select Protocol
P2=<Port> Set Port
P8=<0-6> Set Number of Backlogs

Single Connection Server

Task BSD AT Command AT Command Function
Open Socket P5=1 Create Socket Descriptor
SetSockOpt Set Socket options
Bind Binds Socket to Port
Listen Listens for and queues Client Connections
Accept Returns Socket Descriptor for Client Connection
Send Send S1/S0 or S3 Sends Data
Receive Recv R0 Receives Data
Close Close P5=0 Closes Client Connection Socket Descriptor and Socket Descriptor

Multi-Connection Server – AT Commands

AT Command Response Comments
PK=1,3000 Ok Starts the TCP keep alive
P1=0 Ok Sets connection to TCP
P2=5024 Ok Selects the port ( Note: your firewall may block certain ports. Also, we prefer to use Hercules is you are testing on a PC)
P8=6 Ok Sets the number of backlog requests
P5=11 [TCP TSK] Multi-Accept Setup[TCP SVR] Waiting on connection …OK Start Multi-Accept Server. The modules is waiting for a client to connect
R0 Reads data xxxxx ok R0 = Will read the dataR0= -1 ( This means the connection is lost by either the TCP keep alive or the client)
S3=1\r2 1ok S3 will send a 1 and the response will be 1 byte of data sentS3= -1 ( This means the connection is lost by either the TCP keep alive or the client)
P5=10 [TCP SVR] Waiting on connection …> OK Close and wait for the next connection
P5=0 Ok This actually closes the socket and connection

BSD IWIN Sockets_001

Here is the sequence for using a TCP Multi-accept server. Please remember that TCP is a peer-to-peer connection. This means that only one connection can be handled at a time and once the communication is complete the connection is closed.

Join a network first.
Use P0=0-4 to select socket. If you only have 1 socket you can ignore this command.
>PK=1,3000 // Starts keep alive
>P1=0 //Sets TCP
OK
>P2=5024 //selects port
OK
>P8=6 //Set the number backlog requests (0-6).
OK
>P5=11 //Start Multi-Accept server
[TCP TSK] Multi-Accept Setup
[TCP SVR] Waiting on connection …
OK
[TCP SVR] Accepted 192.168.10.100:34489 //Connection from TCP Client
> R0
Data from 192.168.10.100
OK

> S3=1\r1
1
OK

> P5=10 //Close current and wait for next connection
[TCP SVR] Waiting on connection …
OK
[TCP SVR] Accepted 192.168.10.100:34504 //Connection from TCP Client
> R0
Data from 192.168.10.100
OK
> S3=1\r2
1
OK
> P5=0 //Shutdown server
[TCP TSK] Killed
OK
Please remember when comparing to a Windows server and a internet browser the process
is the same. The browser sends multiple http request and the server handles them sequentially.

TCP+Multi+Accept+Flow

Download (PDF, 58KB)

 

 

2015-06-19T19:17:14+00:00 2019-04-17T15:46:08+00:00