FIXME: toplevel Makefile: 'make ntest' doesn't run versaplexd for now.
[versaplex.git] / dbus-sharp / SocketTransport.cs
blob5389d2f8fe5a200caea0d2844a9fc031bf1a79e0
1 // Copyright 2006 Alp Toker <alp@atoker.com>
2 // This software is made available under the MIT License
3 // See COPYING for details
5 using System;
6 using System.IO;
7 using System.Net;
8 using System.Net.Sockets;
10 namespace NDesk.DBus.Transports
12 class SocketTransport : Transport
14 protected Socket socket;
16 public override void Open (AddressEntry entry)
18 string host, portStr;
19 int port;
21 if (!entry.Properties.TryGetValue ("host", out host))
22 throw new Exception ("No host specified");
24 if (!entry.Properties.TryGetValue ("port", out portStr))
25 throw new Exception ("No port specified");
27 if (!Int32.TryParse (portStr, out port))
28 throw new Exception ("Invalid port: \"" + port + "\"");
30 Open (host, port);
33 public void Open (string host, int port)
35 //TODO: use Socket directly
36 TcpClient client = new TcpClient (host, port);
37 Stream = client.GetStream ();
40 public void Open (Socket socket)
42 this.socket = socket;
44 socket.Blocking = true;
45 SocketHandle = (long)socket.Handle;
46 //Stream = new UnixStream ((int)socket.Handle);
47 Stream = new NetworkStream (socket);
50 public override void WriteCred ()
52 Stream.WriteByte (0);
55 public override string AuthString ()
57 return String.Empty;