HTTP Connections

原创 2004年08月11日 22:34:00

What is HTTP?
The HyperText Transfer Protocol (HTTP) is the application protocol used by the web. This section assumes you have a basic understanding of HTTP version 1.1, as defined in RFC 2616. There is no standard way of using HTTP for interactive applications - the method described here is just the way Microsoft chose to do it. The method described here has nothing to do with the HTTP "CONNECT" method.

How does HTTP work with MSN?
Microsoft use, port 80, as their dispatch server for HTTP connections. Unlike this server has never been seen to transfer clients to another notification server. However, there is a transfer-like function in MSN's HTTP method.

Though HTTP is most often used for transferring HTML documents (hence the name), it's entirely capable of transferring any kind of data. In HTTP, there is no way for the server to send a message to the client without the client requesting it first. MSN Messenger clients send commands in the body of HTTP an request, and the server queues commands to send in the body of a response. When the client has no commands to send for a few seconds, it should "poll" the server for new messages. The official client polls the server once every two seconds.

Once a client has sent an HTTP request, it must wait for the response to come back before sending another request. For example, if you poll the server then send a command without waiting for the response to the poll, you will receive an HTTP 400 error (bad request).

Normally, a single connection to the server is kept alive throughout an MSN Messenger session, but the protocol seems to support a connection being broken and re-established without the session being affected. This has not yet been tested in practice, though.

In your initial profile, the "ClientPort" is set to 0 in an HTTP connection, and sending PNG will cause the server to send an HTTP error and disconnect you. Otherwise, the protocol works as normal.

HTTP Issues in the Official Client
Most of the testing for this page was done with version 5 of the official client, which has fairly poor support for HTTP connections, including several bugs and design flaws. Version 5 is the first even to make the option easily available, so it has presumably not been thoroughly tested. Hopefully, this will be improved in future versions.

The official client misbehaves badly when using HTTP proxies operating on a port other than 80. It doesn't always obey the "one request at a time" rule, so it occasionally gets kicked off with a 400 error. The configuration menu confusingly associates "using an HTTP proxy server" with "using a SOCKS proxy server". The proxy server in an HTTP session performs a completely different function to that in a SOCKS connection, and is most likely not required by the protocol. More seriously, some HTTP proxies are intercept and proxy HTTP connections without the client's knowledge. The official client can't handle these "transparent proxies" at all. Finally, if you specify an HTTP proxy server, the official client will ignore the setting to enable or disable its use. Instead, it will always try to connect directly to MSN Messenger first, then through HTTP if that fails.

Protocol Description
In an HTTP connection, commands are sent to MSN Messenger with POST requests to a CGI script, and received in responses to those commands. The initial request opens a new notification or switchboard server session, and (for a notification server session) should be sent to or (for a switchboard server session) the IP address given in an XFR. Commands you wish to send are contained in the entity-body, one per request (including one in the initial request). When there are no messages to send for a few seconds (two seconds in the official client), the client should poll the server for queued commands.

Server responses contain an "X-MSN-Messenger" header, which includes an IP address to send the next request to and a session ID to send with the next request. If the session is being closed, this header will also include a "Session=close" value. The session ID seems always to be a long number (which remains constant across a session), followed by a dot, then a short number (which changes with each response). Don't rely on this observation - treat it as an arbitrary string.

The official client tries to keep a single connection open throughout a session, though the session ID is presumably included in case a proxy server along the way closes the connection in the middle of a session. Assuming the server doesn't terminate your session when a connection is closed, you must send OUT to close your connection (or wait for a time-out on the server).

The script is /gateway/gateway.dll, and it takes the following arguments:

Either "open" (to open a new session) or "poll" (to receive queued commands without sending any commands). Non-empty requests after the first don't include an "Action" parameter.
Used with "Action=open" to specify the type of server to open. The value can be either "NS" (to open a Notification Server session) or "SB" (to open a switchboard session).
Used with "Action=open" to specify the IP address or domain name of the server.
Sent with every request after the first in a session, this is the string given in the previous response.
The official client sends "Proxy-Connection: Keep-Alive" and "Pragma: No-Cache" headers, which are HTTP/1.0 headers that have been replaced by "Connection: Keep-Alive" in HTTP/1.1. Presumably, these are included incase requests pass through old or buggy proxies on the way to the server. The official client also sends "User-Agent: MSMSGS", though the server doesn't discriminate based on the user-agent.

Examples Requests and Responses
Because the URLs in the HTTP examples are so large, having them on this page caused horizontal scrolling which caused difficulties in reading the information above. You may see the examples in this page.

HTTP1.1 持久连接( Persistent Connections)

8.1持久连接( Persistent Connections)8.1.1目的在提出持久连接之前,每获取一个URL都有创建一个单独的TCP连接,不断的加重HTTP服务器的负担并导致网络的拥塞。使用内联...
  • xiaojianpitt
  • xiaojianpitt
  • 2009-07-27 09:43:00
  • 6567

composer遇到Your configuration does not allow connection to http://的问题怎么解决

有时候composer install/update的时候会报错: [Composer\Downloader\TransportException]                         ...
  • ownfire
  • ownfire
  • 2016-03-18 15:08:00
  • 11116

failed to open stream: HTTP wrapper does not support writeable connections

今天在编程中遇到了如标题所示的报错信息,起因是我想把一些log信息写入到远程的一个txt文件中,代码如下: ...
  • u011250882
  • u011250882
  • 2015-07-24 18:40:56
  • 2552

在使用composer下载TP5的时候遇到 Your configuration does not allow connections to http://packagist.phpcomposer.

在使用composer下载TP5的时候遇到 在使用composer下载TP5的时候遇到  [Composer\Downloader\TransportException]   Your confi...
  • ougexingfuba
  • ougexingfuba
  • 2017-11-28 19:53:09
  • 181

composer 镜像不能访问的问题

最近composer update 总提示:   Your configuration does not allow connection to http://packagist.phpco...
  • 2016-03-17 00:26:49
  • 5000

云之家API获取数据, 关闭Closing connections idle longer than 30 SECONDS

项目获取云之家的数据,写的demo在main方法里面执行没有问题,集成到自己公司的项目中,使用的是SSM框架,每当去获取数据的时候控制台一直跳: 14:05:25,954 INFO [STD...
  • qq_36856975
  • qq_36856975
  • 2017-10-09 17:36:20
  • 344

eclipse 改变联网方式 利用代理服务器 Network Connections
  • zhouhuakang
  • zhouhuakang
  • 2015-04-14 09:01:54
  • 634

netty 连接 No buffer space available (maximum connections reached?): connect

active953 java.lang.IllegalStateException: failed to create a child event loop at io.netty.util.con...
  • AlbertFly
  • AlbertFly
  • 2016-08-16 10:40:13
  • 3353

TeamMgr-1.1 H2内存数据库学习笔记

1. 下载 2. 安装 unzip 3. 启动与停止 仅仅本机web访问控制台 [root@INMSC4 bi...
  • sipsir
  • sipsir
  • 2013-10-06 13:36:17
  • 2205

What is HTTP Persistent Connections?

What is HTTP Persistent Connections? HTTP persistent connections, also called HTTP keep-alive, or H...
  • dong_pongkk999
  • dong_pongkk999
  • 2014-04-22 15:00:15
  • 498
您举报文章:HTTP Connections