<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>深蓝的blog &#187; Socket</title>
	<atom:link href="http://www.lanxinbase.com/?feed=rss2&#038;tag=socket" rel="self" type="application/rss+xml" />
	<link>http://www.lanxinbase.com</link>
	<description>记录日常生活</description>
	<lastBuildDate>Sat, 07 Feb 2026 10:59:52 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.3</generator>
	<item>
		<title>Nginx支持socket转发</title>
		<link>http://www.lanxinbase.com/?p=1787</link>
		<comments>http://www.lanxinbase.com/?p=1787#comments</comments>
		<pubDate>Fri, 24 Nov 2017 02:01:35 +0000</pubDate>
		<dc:creator><![CDATA[Alan]]></dc:creator>
				<category><![CDATA[2.运维相关]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[ngx_stream_core_module]]></category>
		<category><![CDATA[Socket]]></category>

		<guid isPermaLink="false">http://www.lanxinbase.com/?p=1787</guid>
		<description><![CDATA[有个接口是通过socket通信，对端服务器访问存在IP限制，只好通过跳板机，因为它具备访问对端服务器的权限。nginx1.9开始支持tcp层的转发，通过stream实现的，而socket也是基于tcp通信。

一.实现过程：

1.安装nginx，stream模块默认不安装的，需要手动添加参数：–with-stream，官方下载地址：download，根据自己系统版本选择nginx1.9或以上版本。

2.nginx.conf 配置，参考说明：ngx_stream_core_module

nginx.conf

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
.................
}

# tcp层转发的配置文件夹

include /etc/nginx/tcp.d/*.conf;
请注意，stream配置不能放到http内，即不能放到/etc/nginx/conf.d/，因为stream是通过tcp层转发，而不是http转发。

如配置在http内，启动nginx会报如下错误：

nginx: [emerg] "server" directive is not allowed here
3.在tcp.d下新建个bss_num_30001.conf文件，内容如下：]]></description>
		<wfw:commentRss>http://www.lanxinbase.com/?feed=rss2&#038;p=1787</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>android开发:Socket对象使用心跳机制实现服务器与客户端通信</title>
		<link>http://www.lanxinbase.com/?p=1185</link>
		<comments>http://www.lanxinbase.com/?p=1185#comments</comments>
		<pubDate>Thu, 30 Jun 2016 08:16:37 +0000</pubDate>
		<dc:creator><![CDATA[Alan]]></dc:creator>
				<category><![CDATA[7.android应用开发]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[心跳包]]></category>
		<category><![CDATA[心跳机制]]></category>
		<category><![CDATA[服务器与客户端通信]]></category>

		<guid isPermaLink="false">http://www.lanxinbase.com/?p=1185</guid>
		<description><![CDATA[/**
     * 心跳线程,每隔一段时间与服务器通信,发送的数据是:1,也可以制定你们想要的数据
     */
    private Runnable HeartBeatRunnable = new Runnable() {
        @Override
        public void run() {
            if(System.currentTimeMillis() - lastTime >= TAKT_TIME){
                boolean status = sendMsg("1");
                if(!status){
                    mHandler.removeCallbacks(HeartBeatRunnable);
                    releaseLastSocket(mSocket);
                    mReadThread.release();//释放线程
                    initSocket();//重建线程
                }
                mHandler.postDelayed(HeartBeatRunnable, TAKT_TIME);//继续发送心跳包
                Log.d(TAG,"HeartBeatRunnable");
            }
        }
    };]]></description>
		<wfw:commentRss>http://www.lanxinbase.com/?feed=rss2&#038;p=1185</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
