- 浏览: 455772 次
- 性别:
- 来自: 深圳
-
文章分类
最新评论
-
zjhgx:
多谢,多谢。多谢
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
37du:
受教了,对于理解运行过程有很好的效果
ActionMapper---webwork 2.1到2.2 的变化 -
chxiaowu:
非常好,谢谢!
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
euii:
谢谢,这样的总结。
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
xiaoyao3857:
谢谢,正需要这样的汇总型字典!
Ubuntu 中软件的安装、卸载以及查看的方法总结
Articles
Setting Up Socket Streams
You can use the NSStream class to establish a socket connection and, with the stream object (or objects) created as a result, send data to and receive data from a remote host. You can also configure the connection for security.
<!-- This template is being used for both PDF and HTML. --><!-- TopicBook.pm uses this template for its miniTOCs, but needs a different title. -->
Contents:
Basic Procedure
Securing and Configuring the Connection
Initiating an HTTP Request
Basic Procedure
Setting up a socket connection is easy. Just send the NSStream class a getStreamsToHost:port:inputStream:outputStream:
message and you will receive back an object representing an input stream from the remote host or an output stream to the remote host—or both input- and output-stream objects. The getStreamsToHost:port:inputStream:outputStream:
class method merely requires you to provide an NSHost object (identifying the remote host) and a port number.
Listing 1 illustrates the use of getStreamsToHost:port:inputStream:outputStream:
. This example shows the creation of both an NSInputStream object and an NSOutputStream object. If you want to receive only one of these objects, just specify nil
as the parameter value for the unwanted object.
Listing 1 Setting up a network socket stream
- (IBAction)searchForSite:(id)sender { NSString *urlStr = [sender stringValue]; if (![urlStr isEqualToString:@""]) { [searchField setEnabled:NO]; NSURL *website = [NSURL URLWithString:urlStr]; if (!website) { NSLog(@"%@ is not a valid URL"); return; } NSHost *host = [NSHost hostWithName:[website host]]; // iStream and oStream are instance variables [NSStream getStreamsToHost:host port:80 inputStream:&iStream outputStream:&oStream]; [iStream retain]; [oStream retain]; [iStream setDelegate:self]; [oStream setDelegate:self]; [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [iStream open]; [oStream open]; } }
Because the stream objects you receive back from getStreamsToHost:port:inputStream:outputStream:
are autoreleased, be sure to retain them right away. If the socket connection fails, then one or both of the requested NSInputStream and NSOutputStream objects are nil
. Then, as usual, set the delegate, schedule the stream on a run loop, and open the stream. The delegate should begin to receive stream-event messages (stream:handleEvent:
). See “Reading From Input Streams” and “Writing To Output Streams” for more information.
Securing and Configuring the Connection
Before you open a stream object, you might want to set security and other features for the connection to the remote host (which might be, for example, an HTTPS server). NSStream defines properties that affect the security of TCP/IP socket connections in two ways:
-
Secure Socket Layer (SSL).
A security protocol using digital certificates to provide data encryption, server authentication, message integrity, and (optionally) client authentication for TCP/IP connections.
-
SOCKS proxy server.
A server that sits between a client application and a real server over a TCP/IP connection. It intercepts requests to the real server and, if it cannot fulfill them from a cache of recently requested files, forwards them to the real server. SOCKS proxy servers help improve performance over a network and can also be used to filter requests.
For SSL security, NSStream defines various security-level properties (for example, NSStreamSocketSecurityLevelSSLv2
). You set these properties by sending setProperty:forKey:
to the stream object using the key NSStreamSocketSecurityLevelKey
, as in this sample message:
[iStream setProperty:NSStreamSocketSecurityLevelTLSv1 forKey:NSStreamSocketSecurityLevelKey];
You must set the property before you open the stream. Once it opens, it goes through a handshake protocol to find out what level of SSL security the other side of the connection is using. If the security level is not compatible with the specified property, the stream object generates an error event. However, if you request a negotiated security level (NSStreamSocketSecurityLevelNegotiatedSSL
), the security level becomes the highest that both sides of the connection can implement. Still, if you try to set an SSL security level when the remote host is not secure, an error is generated.
To configure a SOCKS proxy server for a connection, you need to construct a dictionary with keys of the form NSStreamSOCKSProxy
NameKey
(for example, NSStreamSOCKSProxyHostKey
). The value of each key is the SOCKS proxy setting that Name refers to. Then using setProperty:forKey:
, set the dictionary as the value of the NSStreamSOCKSProxyConfigurationKey
.
If you know the proxy-server settings, you can construct the dictionary yourself. But an easier way to get a dictionary of current proxy settings is to use the System Configuration framework. To use this API in your program, add SystemConfiguration.framework
to your project and import the <SystemConfiguration/SystemConfiguration.h>
header file. Next, as shown in Listing 2, call the function SCDynamicStoreCopyProxies
and be sure to cast the returned CFDictionary value to an NSDictionary object. Then use this dictionary to set the NSStreamSOCKSProxyConfigurationKey
property.
Listing 2 Setting a stream to the current SOCKS proxy settings
// ... NSDictionary *proxyDict = (NSDictionary *)SCDynamicStoreCopyProxies(NULL); [oStream setProperty:proxyDict forKey:NSStreamSOCKSProxyConfigurationKey]; // ...
For a detailed example of using the System Configuration API to get SOCKS proxy settings, see Technical Q&A QA1234, “Accessing HTTPS Proxy Settings.”
Initiating an HTTP Request
If you are opening a connection to an HTTP server (that is, a website), then you may have to initiate a transaction with that server by sending it an HTTP request. A good time to make this request is when the delegate of the NSOutputStream object receives a NSStreamEventHasSpaceAvailable
event via a stream:handleEvent:
message. Listing 3 shows the delegate creating an HTTP GET request and writing it to the output stream, after which it immediately closes the stream object.
Listing 3 Making an HTTP GET request
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode { NSLog(@"stream:handleEvent: is invoked..."); switch(eventCode) { case NSStreamEventHasSpaceAvailable: { if (stream == oStream) { NSString * str = [NSString stringWithFormat: @"GET / HTTP/1.0\r\n\r\n"]; const uint8_t * rawstring = (const uint8_t *)[str UTF8String]; [oStream write:rawstring maxLength:strlen(rawstring)]; [oStream close]; } break; } // continued ... } }
Related Reference
Objective-C
发表评论
-
OLAP与OLTP
2011-02-10 13:51 1602当今的数据处理大致可 ... -
VPS主机技术原理
2011-01-11 11:42 1341VPS主机是一项服务器虚拟化和自动化技术 ,它采用的是操 ... -
学习STL map, STL set之数据结构基础
2010-12-23 09:45 2094学习STL map, STL set之数据结构基础 ... -
经典的排错过程 expected unqualified-id before string constant
2010-10-20 18:52 11137答案是:我的代码少了一个 “;” ============= ... -
命令行输出彩色字符串
2010-09-30 14:13 1737#include int main (int argc, ... -
source Insight常用自定义命令和一些小技巧
2010-08-13 14:34 4398在Source Insight中添加自定义功能的步骤如下: ... -
WEB服务器性能瓶颈分析
2010-07-29 15:15 1651本文先介绍一下各种WEB ... -
10个强大的开源Web流量分析工具
2010-06-18 20:18 2561锐商企业CMS 写道 & ... -
URL Encoding
2010-06-10 20:45 1538URL:http://localhost:8080/examp ... -
Trie- 字典树(单词树)的基本应用
2010-05-12 14:47 1381#include <stdio.h> #inc ... -
HTTP 1.1的一些细节:Cache机制
2010-05-08 13:38 1649HTTP 1.1的一些细节:Cache机制 ... -
Web缓存加速指南
2010-05-08 12:15 914原文(英文)地址: http://www.mnot.net/c ... -
RGB 转换至 YCbCr (YUV) 的计算公式
2010-03-28 12:46 9337对于每个取样点的 R,G,B 值, 在转换到 YUV colo ... -
理解I/O Completion Port
2010-03-13 10:42 1422欢迎阅读此篇IOCP教程。我将先给出IOCP的定义然后给出它的 ... -
右左法则
2010-03-06 17:30 1275The right-left rule: Start rea ... -
关于IO ports和IO memory
2009-12-21 15:30 2212在IA32 Manuals-Basic Architectur ... -
C++类型转换运算符的使用方法
2009-12-21 14:34 1341C++的四个类型转换运算符已经有很久了,但一直没有弄清楚它们的 ... -
C/C++关键字static,const,inline,define,typedef
2009-12-21 14:13 2068一 static 1) 产生背景 ... -
Keyword volatile in C Programming Language
2009-12-21 14:06 935volatile关键字是一种类 ... -
C/C++位域(Bit-fields)之我见
2009-12-13 17:29 2151原文 : http://blog.csdn.net/ztz02 ...
相关推荐
6. **Setting Up Socket Streams** (Page 22): Guides through setting up and configuring socket streams for network communication. #### Cocoa Streams Streams in Cocoa are primarily represented by three...
Socket Streams Library 是一个开源项目,它为 C++ 开发者提供了一个方便的接口,将标准库中的 IOStreams 功能扩展到了 POSIX 套接字上。这个库的主要目的是简化网络编程,尤其是涉及到套接字通信时的数据读写操作。...
Ntfs数据流处理工具NtfsStreamsEditor提供了强大的搜索扫描能力,帮助找出危险所在;同时NtfsStreamsEditor提供了最强大的删除、附加、导入、导出、备份和还原等完整处理手段,是Ntfs数据流处理必备的工具。 Ntfs...
Get an easy introduction to reactive streams in Java to handle concurrency, data streams, and the propagation of change in today's applications. This compact book includes in-depth introductions to ...
Oracle Streams是一种先进的数据复制解决方案,它允许用户在Oracle数据库之间实时传输数据,从而实现数据库的复制、归档、故障恢复和读写分离等多种功能。在本配置文档中,你将找到有关Oracle Streams的全面信息,...
CFStream API是苹果提供的Core Foundation框架的一部分,可用于处理套接字流(socket streams)。这个API支持TCP和UDP协议,可以用于创建双向的数据流。CFStream创建的流可以是本地的(例如,与另一个进程通信)或...
reactive-streams-1.0.3.jar
`web-streams-polyfill` 是一个开源库,它实现了WHATWG 规范中的大部分 Web Streams API,使得开发者可以在不支持原生 Web Streams 的环境中也能使用这一强大的功能。这个库主要包含以下几个部分: 1. **...
### Oracle Streams 概念与管理 #### 一、Oracle Streams 简介 Oracle Streams 是一个强大而灵活的数据复制和集成解决方案,它为 Oracle 数据库提供了实时的数据捕获、传输和应用功能。此技术主要用于数据库之间的...
它的流处理组件Kafka Streams,允许用户在数据流进Kafka之后进行实时的流处理。Kafka Streams是一个轻量级的库,可以嵌入到任何Java应用程序中。使用Kafka Streams,开发者可以轻松地构建实时应用程序和微服务。 在...
赠送jar包:reactive-streams-1.0.3.jar; 赠送原API文档:reactive-streams-1.0.3-javadoc.jar; 赠送源代码:reactive-streams-1.0.3-sources.jar; 赠送Maven依赖信息文件:reactive-streams-1.0.3.pom; 包含...
在描述中提到的"NtfsStreamsEditor2.rar"是一个可能用于查看、编辑或提取这些隐藏NTFS流的工具。这类工具可以帮助安全研究人员、CTF挑战者或系统管理员探索系统中可能隐藏的信息。使用NtfsStreamsEditor2,用户可以...
赠送jar包:reactive-streams-1.0.3.jar; 赠送原API文档:reactive-streams-1.0.3-javadoc.jar; 赠送源代码:reactive-streams-1.0.3-sources.jar; 赠送Maven依赖信息文件:reactive-streams-1.0.3.pom; 包含...
2. 隐蔽流(Alternate Data Streams, ADS):除了主流之外的其他数据流,它们不会在文件资源管理器中显示,通常需要特定工具才能查看和操作。 `ntfsstreamseditor`是一个用于管理和编辑NTFS流文件的工具,它可以...
《Kafka Streams实战》这本书是了解和掌握Apache Kafka的流处理框架Kafka Streams的重要资源。Kafka Streams是一个轻量级的库,允许开发者在Java或Scala应用中直接处理流数据,无需部署额外的集群服务。它将复杂的...
### 高清彩版 Kafka Streams in Action:深入解析 #### 一、背景介绍与书籍概述 《Kafka Streams in Action》是一本专为希望深入了解Kafka Streams及其在实时数据流处理应用中的实践而编写的书籍。作者Bill Bejeck...
Oracle Streams 是Oracle数据库提供的一种强大的数据流和事件流解决方案,它允许在单个数据库内或跨多个数据库之间高效地移动数据和事件。Streams的核心功能包括数据捕获、传播和服务应用,支持显式(通过编程方式)...
Reactive Streams in Java Concurrency with RxJava, Reactor, and Akka Streams. 2019年最新出版,清晰文字PDF,带目录书签。
本文将深入探讨"Streaming Architecture New Designs Using Apache Kafka and MapR Streams"这一主题,阐述如何利用这两种强大的工具构建高效、可扩展的流处理系统。 Apache Kafka是一种分布式流处理平台,由...
它引入了许多先进的特性,其中数据流(alternate data streams, ADS)是一个非常独特且在日常使用中不太为人所知的功能。"ntfsstreamseditor"是一款专门针对NTFS分区文件数据流进行操作的工具,它允许用户对数据流...