How can I make a simple tcp socket listener? The f...
# announcements
k
How can I make a simple tcp socket listener? The following python code does the job
Copy code
python
import socket

IP = "127.0.0.1"
PORT = 25565

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_STREAM)
sock.bind((IP, PORT))
sock.listen(1)
conn, addr = sock.accept()
try:
	while True:
		data = conn.recv(1024)
		if not data: break
		print(*(hex(i)[2:].rjust(2,'0') for i in data))
finally:
	conn.close()
but I can't seem to find an easy solution in kotlin
d
Consider using ktor. There's a channel too, #C0A974TJ9 .
k
Thanks