Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* compile with: valac server.vala --pkg gio-2.0 */
- async void handleConnection(GLib.SocketConnection connection) throws GLib.IOError
- {
- while (true) {
- var buffer = new uint8[1024];
- yield connection.input_stream.read_async(buffer);
- stdout.printf("%s", (string)buffer);
- }
- }
- async void server() throws GLib.Error
- {
- var listener = new GLib.SocketListener();
- listener.add_inet_port(5555, null);
- while(true) {
- var connection = yield listener.accept_async();
- handleConnection.begin(connection);
- }
- }
- int main()
- {
- var loop = new GLib.MainLoop(null, false);
- server.begin();
- loop.run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement