Advertisement
qasync

A Simple TCP Server - in Vala this time

Sep 14th, 2011
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.66 KB | None | 0 0
  1. /* compile with: valac server.vala --pkg gio-2.0 */
  2.  
  3. async void handleConnection(GLib.SocketConnection connection) throws GLib.IOError
  4. {
  5.     while (true) {
  6.         var buffer = new uint8[1024];
  7.     yield connection.input_stream.read_async(buffer);
  8.     stdout.printf("%s", (string)buffer);
  9.     }
  10. }
  11. async void server() throws GLib.Error
  12. {
  13.     var listener = new GLib.SocketListener();
  14.     listener.add_inet_port(5555, null);
  15.     while(true) {
  16.         var connection = yield listener.accept_async();
  17.     handleConnection.begin(connection);
  18.     }
  19. }
  20. int main()
  21. {
  22.     var loop = new GLib.MainLoop(null, false);
  23.     server.begin();
  24.     loop.run();
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement