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.

MySQL提示“too many connections”的解决办法

今天生产服务器上的MySQL出现了一个不算太陌生的错误“Too many connections”。平常碰到这个问题,我基本上是修改/etc/my.cnf的max_connections参数,然后重启...
  • qq43599939
  • qq43599939
  • 2017年04月03日 20:00
  • 1911

mysql5.6 too many connections问题解决及其他参数设置

mysql5.6中没有my.ini,所以在出现too many connections时候一时不知道怎么设置,
  • niyabuxing
  • niyabuxing
  • 2014年06月30日 11:43
  • 2705

关于too many connections问题产生原因的理解

产生too many connections 的直接原因是因为数据库提供的连接被全部占满了。数据库可以提供多少连接,可以再my.cnf(linux)或者my.ini(windows)下设定。这个直接原...
  • wyxz126
  • wyxz126
  • 2013年02月24日 15:02
  • 1307

【mysql】提示“too many connections”的解决办法

最近使用java多线程连接mysql打数据,安装好mysql后,使用500线程连接发现提示:too many connections, 查询方法得知是需要进行配置才行: 产生这种问题的原因是: 连接数...
  • hj7jay
  • hj7jay
  • 2017年01月16日 10:22
  • 1301

安装MongoDB 并设置成服务

安装MongoDB 1 下载: 这不用多说,下载对应系统的32/64位安装包 ...
  • LXB15959168136
  • LXB15959168136
  • 2016年08月12日 10:07
  • 2301


1、背景:在网页自动化测试和网页表单自动交互的场景中,对动态js页面的加载,隐藏链接爬虫和表单元素需要加载js来解析。                   htmlunit相比较于htmlparser...
  • fjssharpsword
  • fjssharpsword
  • 2016年11月15日 10:21
  • 2473

tcpcopy 上手介绍和测试说明

  • caisini_vc
  • caisini_vc
  • 2017年06月16日 15:55
  • 497


Networking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8557   Acc...
  • Bear1998
  • Bear1998
  • 2016年08月02日 21:10
  • 413

Rails中实现后台处理:Redis, Sidekiq 使用总结

Redis用法 在Linux中安装Redis命令 $ wget
  • remote_roamer
  • remote_roamer
  • 2013年11月19日 22:03
  • 15445

HDU2874——Connections between cities 详解 (LCA,RMQ,数据结构,dfs序,并查集)

Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (...
  • say_c_box
  • say_c_box
  • 2016年07月26日 11:53
  • 366
您举报文章:HTTP Connections