HttpWebRequest/Response in a Duplex way?
-
Hello, i want to communicate between a client/server application with HttpWebRequest an HttpWebResponse. My problem is, that i have a server farm. I want to have sessions and want to be able to send and receive informations. The problem is now, that i can't really work like a web-Server. A request and i deliver a response. I need to talk on one connection in a duplex way. So is it possible to create a HttpWebRequest and to send informations in it, receive some informations and use the same Request(Connection) for sending another Informations? Thank you
-
Hello, i want to communicate between a client/server application with HttpWebRequest an HttpWebResponse. My problem is, that i have a server farm. I want to have sessions and want to be able to send and receive informations. The problem is now, that i can't really work like a web-Server. A request and i deliver a response. I need to talk on one connection in a duplex way. So is it possible to create a HttpWebRequest and to send informations in it, receive some informations and use the same Request(Connection) for sending another Informations? Thank you
Hello SoftwareJaeger, The short answer is NO, HttpWebRequest/Response is just that a single request and response. You can constantly open, close and re-use them all you like but you are not going to get the bi-directional (or duplex) communication you are looking for. What you need is to actually open TCP or UDP sockets and then send all your calls from there. Really a very basic example would be a chat client (i.e. Windows Live Messenger) which implements the type of functionality you want. There is a great little article here on CP that will walk you through creating a chat client with UDP sockets here[^] that will illustrate the principals of what it is that you need to do.
Don't comment your code - it was hard to write, it should be hard to read!
-
Hello, i want to communicate between a client/server application with HttpWebRequest an HttpWebResponse. My problem is, that i have a server farm. I want to have sessions and want to be able to send and receive informations. The problem is now, that i can't really work like a web-Server. A request and i deliver a response. I need to talk on one connection in a duplex way. So is it possible to create a HttpWebRequest and to send informations in it, receive some informations and use the same Request(Connection) for sending another Informations? Thank you
A little back story to Adam's response: HTTP is a stateless protocol. You fire, and you're not necessarily guaranteed a response. In some web farms sessions are maintained across servers, but in others, the sessions are load balanced. You should be able to rely on session data, but it is still not proper stateful communication. The client makes a request (breaking it down, even, in multi-part scenarios). The server fulfills the request (by returning a status code and possibly payload). That is the end of com. As Adam suggested, you'll need to drop to a different protocol/level to achieve what you're looking for and maintain the open connection. Cheers.