6 // Todd Berman <tberman@imeem.com>
8 // Copyright (C) 2007 imeem, inc. <http://www.imeem.com>
9 // All rights reserved.
13 using System
.Collections
.Generic
;
15 using System
.Net
.Sockets
;
17 namespace Thrift
.Transport
19 public class TSocket
: TStreamTransport
21 private TcpClient client
= null;
22 private string host
= null;
24 private int timeout
= 0;
26 public TSocket(TcpClient client
)
32 inputStream
= client
.GetStream();
33 outputStream
= client
.GetStream();
37 public TSocket(string host
, int port
) : this(host
, port
, 0)
41 public TSocket(string host
, int port
, int timeout
)
45 this.timeout
= timeout
;
50 private void InitSocket()
52 client
= new TcpClient();
53 client
.ReceiveTimeout
= client
.SendTimeout
= timeout
;
60 client
.ReceiveTimeout
= client
.SendTimeout
= timeout
= value;
64 public TcpClient TcpClient
72 public override bool IsOpen
81 return client
.Connected
;
85 public override void Open()
89 throw new TTransportException(TTransportException
.ExceptionType
.AlreadyOpen
, "Socket already connected");
92 if (String
.IsNullOrEmpty(host
))
94 throw new TTransportException(TTransportException
.ExceptionType
.NotOpen
, "Cannot open null host");
99 throw new TTransportException(TTransportException
.ExceptionType
.NotOpen
, "Cannot open without port");
107 client
.Connect(host
, port
);
108 inputStream
= client
.GetStream();
109 outputStream
= client
.GetStream();
112 public override void Close()