- 浏览: 232742 次
文章分类
- 全部博客 (160)
- java语言基础 (67)
- jsp基础 (2)
- eclipse使用 (2)
- java源码解读 (6)
- 计算机基础 (3)
- eclipse插件 (0)
- 网络基础 (8)
- 算法 (2)
- linux (0)
- 英语 (0)
- C语言 (4)
- JavaScript (17)
- 数学 (0)
- struts2 (2)
- 自然哲学 (0)
- Servlet (1)
- HttpServer (2)
- ext (1)
- 个人 (1)
- dojo (27)
- spring (2)
- hibernate (4)
- css (3)
- 多线程 (0)
- chrome插件开发 (0)
- svn (0)
- thrift (2)
- phonegap (1)
- java线程 (1)
- 不是很熟悉的css属性 (0)
- 数据库性能调优 (0)
- 项目管理 (1)
- ios (0)
- 软件工程 (0)
- db2 (0)
- 词汇管理 (0)
- zhenyan (0)
- 计划 (0)
- android (0)
- ssss (0)
- 是的 (0)
- dsada (0)
- 泛点是 (0)
- fds (0)
- cxzc (0)
- 权限 (0)
- dfsfds (0)
- http://www.cnblogs.com/kingboy2008/p/5261771.html (0)
- sss (0)
- ddd (0)
- fdsfdsf (0)
- sso (0)
- nginx (0)
- 分布式数据一致性 (0)
- mysql (0)
- ios永久存储 (0)
- js匿名函数 (0)
- 打印机qqq (0)
最新评论
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; /** * Socket implementation of the TTransport interface. To be commented soon! * */ public class TSocket extends TIOStreamTransport { private static final Logger LOGGER = LoggerFactory.getLogger(TSocket.class.getName()); /** * Wrapped Socket object */ private Socket socket_ = null; /** * Remote host */ private String host_ = null; /** * Remote port */ private int port_ = 0; /** * Socket timeout */ private int timeout_ = 0; /** * Constructor that takes an already created socket. * * @param socket Already created socket object * @throws TTransportException if there is an error setting up the streams */ public TSocket(Socket socket) throws TTransportException { socket_ = socket; try { socket_.setSoLinger(false, 0); socket_.setTcpNoDelay(true); } catch (SocketException sx) { LOGGER.warn("Could not configure socket.", sx); } if (isOpen()) { try { inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } } } /** * Creates a new unconnected socket that will connect to the given host * on the given port. * * @param host Remote host * @param port Remote port */ public TSocket(String host, int port) { this(host, port, 0); } /** * Creates a new unconnected socket that will connect to the given host * on the given port. * * @param host Remote host * @param port Remote port * @param timeout Socket timeout */ public TSocket(String host, int port, int timeout) { host_ = host; port_ = port; timeout_ = timeout; initSocket(); } /** * Initializes the socket object */ private void initSocket() { socket_ = new Socket(); try { socket_.setSoLinger(false, 0); socket_.setTcpNoDelay(true); socket_.setSoTimeout(timeout_); } catch (SocketException sx) { LOGGER.error("Could not configure socket.", sx); } } /** * Sets the socket timeout * * @param timeout Milliseconds timeout */ public void setTimeout(int timeout) { timeout_ = timeout; try { socket_.setSoTimeout(timeout); } catch (SocketException sx) { LOGGER.warn("Could not set socket timeout.", sx); } } /** * Returns a reference to the underlying socket. */ public Socket getSocket() { if (socket_ == null) { initSocket(); } return socket_; } /** * Checks whether the socket is connected. */ public boolean isOpen() { if (socket_ == null) { return false; } return socket_.isConnected(); } /** * Connects the socket, creating a new socket object if necessary. */ public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (host_.length() == 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (port_ <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } if (socket_ == null) { initSocket(); } try { socket_.connect(new InetSocketAddress(host_, port_), timeout_); inputStream_ = new BufferedInputStream(socket_.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } } /** * Closes the socket. */ public void close() { // Close the underlying streams super.close(); // Close the socket if (socket_ != null) { try { socket_.close(); } catch (IOException iox) { LOGGER.warn("Could not close socket.", iox); } socket_ = null; } } }
发表评论
-
ProcessFunction
2012-07-14 22:27 0public abstract class Proces ... -
TBaseProcessor
2012-07-14 22:25 0public abstract class TBaseP ... -
TProcessor
2012-07-14 22:19 0/** * A processor is a gen ... -
TBase
2012-07-14 22:17 0/** * Generic base interfa ... -
TJSONProtocol
2012-07-14 22:16 0/** * JSON protocol implem ... -
TMessage
2012-07-14 21:13 0/** * Helper class that en ... -
TProtocol
2012-07-14 21:12 0/** * Protocol interface d ... -
TNonblockingTransport
2012-07-14 21:02 0public abstract class TNonbl ... -
TNonblockingSocket
2012-07-14 21:02 0/** * Transport for use wi ... -
TFileTransport
2012-07-14 20:57 0/** * FileTransport implem ... -
AutoExpandingBufferReadTransport
2012-07-14 20:48 0/** * TTransport for readi ... -
AutoExpandingBuffer
2012-07-14 20:46 0/** * Helper class that wr ... -
TServerTransport
2012-07-14 20:43 0/** * Server transport. Ob ... -
TServerSocket
2012-07-14 20:43 0/** * Wrapper around Serve ... -
TIOStreamTransport
2012-07-14 20:40 0/** * This is the most com ... -
TTransport
2012-07-14 20:37 2380package org.apache.thrift.tr ...
相关推荐
"delphi tsocket"标签进一步确认了这是与Delphi编程语言和TCP/IP套接字(Sockets)技术相关的组件。 Delphi是Borland公司开发的一种集成开发环境(IDE),广泛用于创建Windows和Web应用程序。它基于Object Pascal...
#if defined AFX TSOCKET H ECFF7A02 DCAF 455D 97C3 0C1D465D977B INCLUDED #define AFX TSOCKET H ECFF7A02 DCAF 455D 97C3 0C1D465D977B INCLUDED #if MSC VER > 1000 #pragma once #endif MSC VER > ...
在IT领域,网络通信是不可或缺的一部分,而QT作为一个强大的跨平台开发框架,提供了丰富的网络通信功能,其中包括TCP(传输控制协议)套接字。本文将深入探讨如何在QT环境中使用TCP套接字来传递结构体信息,这在很多...
`TSocket.cpp`包含了`TSocket`类的实现,这是一个封装了套接字操作的类。这个类可能会有打开、关闭套接字、绑定、监听、接受连接、发送和接收数据等方法。由于IOCP模型是基于套接字的,所以`TSocket`类是整个框架与...
它创建了一个`TSocket`对象,指定HBase服务器的IP地址和端口号,然后创建`TBinaryProtocol`实例和`Hbase.Client`对象,打开连接并调用`getRow`方法来获取指定表和行的数据。 5. **启动服务**:在运行C#客户端之前,...
TTransport(负则传输的模块,就是底层I/O的实现):每一种传输方式都对应一个该模块,比如TSocket负则Socket通信,负责传输的对象就是Message。 TProtocol:这个就是协议模块,因为对Message的传输需要统一,否则就...
transport = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol) try: ...
TSocket* socket = new TSocket("localhost", 9090); TBufferedTransport* transport = new TBufferedTransport(socket); TBinaryProtocol* protocol = new TBinaryProtocol(transport); MyServiceClient client...
ASock, MainSock: TSocket; len, i: Integer; begin MainSock := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); addr.sin_family := AF_INET; addr.sin_port := htons(5678); addr.sin_addr.S_addr := htonl...
$transport = new TSocket('localhost', 9090); $protocol = new TBinaryProtocol($transport); $client = new MyServiceClient($protocol); $transport->open(); $result = $client->hello('World'); $transport->...
transport = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(transport) # 创建协议实例 protocol = TBinaryProtocol.TBinaryProtocol(transport) # 创建HBase客户端 client = ...
1. Transport:Thrift提供了多种Transport方式,包括TSocket、TFileTransport、TZlibTransport、TBufferedTransport和TFramedTransport。这些Transport方式可以根据需要选择,例如TSocket用于 socket 通信,...
socket = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) handler = HelloServiceImpl() processor = processor...
在服务器端,我们需要创建一个`TProcessor`实例(这里是`helloworld::HelloWorldProcessor`),然后绑定到一个`TSocket`或更高级的传输层,如`TFramedTransport`。接着,我们可以启动一个`TServer`(如`...
transport = TSocket.TSocket('10.134.113.75', 1234) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Client(protocol) transport....
transport = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Client(protocol) transport.open...
在C++中,标准库中没有提供多线程安全的字符串操作,所以"cstring.cpp"可能是为了提供线程安全的字符串操作,而"tSocket.cpp"可能是一个封装了线程安全特性的套接字类,确保在网络通信中的并发操作不会引发问题。...
客户端则创建一个`TTransport`对象(如`TSocket`)连接到服务器,然后构建一个`TProtocol`,并通过`TestService$Client`与服务交互: ```java public class Client { public static void main(String[] args) ...