#!/usr/local/bin/tt

:r disp_sockinfo

### ECHO SERVER ###
if( argc!=3 )
	dying("Usage[EchoServer(UDP)]: %s SV-IP SV-Port\n",CMD);

ip  =shift()							# (String) "127.0.0.1"|"localhost"
port=shift()							# (String) "7"        |"echo"

# サーバー用ソケットの作成
sock=udp_socket(ip,port)
if( sock==NULL )
	dying("Error: cannot make socket!!\n")

disp_sockinfo(sock)

while(TRUE){

	# 受信(デフォルトソケットを利用)
	(ip,port,buf,len)=rx_udp()
	print("From: IP=%s Port=%d Message=\"%s\"(Lenght=%d)\n",ip2str(ip),port,buf,len)

	disp_sockinfo(sock)

	# 送信(デフォルトソケットを利用)
	ret = tx_udp(ip,port,buf,len)
	print("To  : IP=%s Port=%d Message=\"%s\"(Length=%d)\n",ip2str(ip),port,buf,len)

	disp_sockinfo(sock)

}
