A script language of preemptive scheduling coroutine in single thread
This document introduces a set of functions about TCP and UDP in Melang.
create a TCP connection to server.
@mln_tcpConnect(host, service, timeout);
Input:
Return value:
Set up a TCP listen socket.
@mln_tcpListen(host, service);
Input:
Return value:
Accept a TCP connection.
@mln_tcpAccept(listenfd, timeout);
Input:
Return value:
Send ‘data’ via TCP.
@mln_tcpSend(sockfd, data);
Input:
Return value:
Receive data from TCP.
@mln_tcpRecv(sockfd, timeout);
Input:
Return value:
Close a TCP connection.
@mln_tcpClose(sockfd);
Input:
Return value:
Shutdown TCP connection.
@mln_tcpShutdown(sockfd, mode);
Input:
Return value:
Create an UDP socket.
@mln_udpCreate(host, service);
Input:
Return value:
Close an UDP socket.
@mln_udpClose(fd);
Input:
Return value:
Send data via UDP.
@mln_udpSend(fd, data, host, service);
Input:
Return value:
Receive data from UDP.
@mln_udpRecv(fd, bufsize, &ip, &port, timeout);
Input:
Return value:
//client.mln
fd = @mln_tcpConnect('127.0.0.1', '1234');
@mln_print(fd);
@mln_tcpSend(fd, 'Hello');
@mln_print(@mln_tcpRecv(fd));
@mln_tcpClose(fd);
//server.mln
listenfd = @mln_tcpListen('127.0.0.1', '1234');
connfd = @mln_tcpAccept(listenfd);
@mln_print(@mln_tcpRecv(connfd));
@mln_tcpSend(connfd, 'Hi');
@mln_tcpClose(connfd);
$ melang server.mln client.mln
The output is:
10
Hello
Hi