7.1.1 peer-to-peer, client 예제 - 문자열 송수신
UDP peer-to-peer
# 1. enet 모듈 import 후, 생성자로 ENet 객체 생성
import enet
var cli=enet.ENet() # TCP 통신인 경우, ENet("tcp")
# 2. IP주소와 port번호 설정
cli.ip_addr="192.168.1.172" # remote (상대방) IP address
cli.lport=51001 # local (자신) port
cli.rport=51002 # remote (상대방) port
# (port no. 49152–65535(except 50000~50005) contains dynamic or private ports)
# 3. ethernet socket 열기
cli.open
print cli.state() # 1이면 정상
# --------------------------------
# 4-1. string 송신
cli.send "hello, peer.\n"
# 4-2. string 수신
# (5초간 수신 없으면 *TimeOut 레이블로 jump)
var msg
cli.recv 5000, *TimeOut
var msg=result() # 수신된 문자열
print msg
delay 1.0
# --------------------------------
# 5. ethernet socket 닫기
cli.close
print cli.state() # 0이면 정상
delay 1.5
end
*TimeOut
print "time out!"
cli.close
endTCP client
Last updated
Was this helpful?