locked
WP7用socket实现HTTP中的Keep-Alilve字段 RRS feed

  • 问题

  • 急求解决方案:

    在实现过程中遇到问题,我保持了上次连接的socket并检查了socket状态,确实是连接的,当下一次请求用这个socket发送数据的时候,socket的事件响应函数不能响应,请问 有人知道怎么解决吗?


    OK, please notice me
    2011年9月27日 3:09

答案

  • APP HUB上有相同问题的讨论,以下内容希望对您有所帮助。

    http://forums.create.msdn.com/forums/t/83353.aspx

     

    As a workaround, the server can keep track of the phone clients' connection state and data, including monitoring connect and shutdown events, as well as using a timeout mechanism, perhaps in conjunction with periodic "keep alive" messages from the phone clients.

     

    This is a very simple example of how you can do basic tcp socket communication with a wp7 client: SimpleClientSocket.cs
    The class provides a connect(), send() and close() method and you are notified through events about received data, an established connection or a disconnect.
    Works fine for me. Ofcourse there are things to improve and add, but it might be a good starting point.


    Cedar
    2011年9月27日 7:02
    版主

全部回复

  • 请参考Windows Phone的socket模型。

    Sockets Support on Windows Phone


    Windows Phone provides the programming interface needed to create and use TCP and UDP sockets. You can select which type of socket to use based on your application’s needs. The following diagram shows a view of the operations that take place during a communication session between a client application and a service. For an explanation of the terms used, see Terminology.

    Sequence Diagram of Socket Communication

    Cedar
    2011年9月27日 6:22
    版主
  • 首先,非常感谢你的详细解答, 有没有一段wp7中socket实现keep-alive的代码,我知道能保存socket的连接,socket去连接、发送、接收都要用到一个SocketAsynsEventArgs 对象,不然没发去操作,基本这个对象 ,在第二次放松数据的时候,事件响应有点问题。 能给出一段 简单的 实现代码吗?
    OK, please notice me
    2011年9月27日 6:48
  • APP HUB上有相同问题的讨论,以下内容希望对您有所帮助。

    http://forums.create.msdn.com/forums/t/83353.aspx

     

    As a workaround, the server can keep track of the phone clients' connection state and data, including monitoring connect and shutdown events, as well as using a timeout mechanism, perhaps in conjunction with periodic "keep alive" messages from the phone clients.

     

    This is a very simple example of how you can do basic tcp socket communication with a wp7 client: SimpleClientSocket.cs
    The class provides a connect(), send() and close() method and you are notified through events about received data, an established connection or a disconnect.
    Works fine for me. Ofcourse there are things to improve and add, but it might be a good starting point.


    Cedar
    2011年9月27日 7:02
    版主