From: Lucas Bajolet Date: Fri, 2 May 2014 19:05:30 +0000 (-0400) Subject: lib/socket: Simplified API for Sockets X-Git-Tag: v0.6.6~86^2~8 X-Git-Url: http://nitlanguage.org lib/socket: Simplified API for Sockets Signed-off-by: Lucas Bajolet --- diff --git a/examples/socket_client.nit b/examples/socket_client.nit index d9ac5ff..0ba1913 100644 --- a/examples/socket_client.nit +++ b/examples/socket_client.nit @@ -24,7 +24,7 @@ if args.length < 2 then return end -var s = new Socket.stream_with_host(args[0], args[1].to_i) +var s = new Socket.client(args[0], args[1].to_i) print "[HOST ADDRESS] : {s.address}" print "[HOST] : {s.host}" print "[PORT] : {s.port}" diff --git a/examples/socket_server.nit b/examples/socket_server.nit index 8754ce2..aa77a75 100644 --- a/examples/socket_server.nit +++ b/examples/socket_server.nit @@ -24,7 +24,7 @@ if args.is_empty then return end -var socket = new Socket.stream_with_port(args[0].to_i) +var socket = new Socket.server(args[0].to_i, 1) print "[PORT] : {socket.port.to_s}" var clients = new Array[Socket] diff --git a/lib/mpd.nit b/lib/mpd.nit index cf9b677..9a56b95 100644 --- a/lib/mpd.nit +++ b/lib/mpd.nit @@ -34,8 +34,7 @@ class MPDConnection do var p: nullable Socket = null - p = new Socket.stream_with_host(host, port) - p.connect + p = new Socket.client(host, port) sys.nanosleep(0,5000) diff --git a/lib/socket/socket.nit b/lib/socket/socket.nit index 4a5129e..9824111 100644 --- a/lib/socket/socket.nit +++ b/lib/socket/socket.nit @@ -44,7 +44,7 @@ class Socket redef var end_reached = false # Creates a socket connection to host `thost` on port `port` - init stream_with_host(thost: String, tport: Int) + init client(thost: String, tport: Int) do _buffer = new FlatBuffer _buffer_pos = 0 @@ -62,8 +62,8 @@ class Socket if not end_reached then end_reached = not connect end - # Creates a server socket on port `tport` - init stream_with_port(tport: Int) + # Creates a server socket on port `tport`, with a connection queue of size `max` + init server(tport: Int, max: Int) do _buffer = new FlatBuffer _buffer_pos = 0