Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- load_netlayer:-
- create_netlayer_server(Socket, Port, Stream),
- thread_create(handle_incoming_connections(Stream), NetLayerThread, [detached(true)]).
- handle_incoming_connections(Stream):-
- write('waiting to connect'),
- tcp_accept(Stream, ClientSocket, ClientIP),
- write('accepted connection!'),
- thread_create(create_client(ClientSocket, ClientIP), ClientThread, [detatched(true)]),
- handle_incoming_connections(Stream).
- create_client(Socket, IP):-
- setup_call_cleanup(tcp_open_socket(Socket, Stream), handle_client(Socket, IP, Stream), close_connection(Stream)).
- create_netlayer_server(Socket, Port, Stream):-
- Port = 42069,
- tcp_socket(Socket),
- tcp_bind(Socket, Port),
- tcp_listen(Socket, 5),
- tcp_open_socket(Socket, Stream).
- handle_client(Socket, IP, Stream):-
- writef('hello %w %w', [Socket, IP]).
- close_connection(Stream):-
- close(Stream).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement