Is it possible to transfer data stream via HTTP or FTP protocol instead of TCP/IP
The requirement is to transfer bytes data stream(in bytes format) through HTTP or FTP protocol. I am doing it with IP protocol but as it is unable to be handled by load balancers. Right now I am sending data stream by converting into byte format and at receiver's end decoding it into string form. The same thing I wanna do with HTTP protocol.
Socket sock = new Socket(Addr开发者_如何学编程essFamily.InterNetwork,
SocketType.Stream, ProtocolType.IP);
Here in ProtocolType.IP
there should be HTTP but HTTP option is not there.
This is a WinForms application.
HTTP isn't a protocol at that level - it's an application level protocol.
You don't get "an HTTP socket" - you typically get a TCP/IP socket and write HTTP data over that.
See the OSI model for more details about the network layers involved.
I don't know for sure whether the built-in HTTP client libraries in .NET support streaming requests... you'd probably want to turn buffering off and write to the request stream. See what that looks like at the socket level using something like WireShark.
The ProtocolType
enumeration does not include HTTP. HTTP is part of the application layer in the OSI model. There has never been a concept of a "HTTP Socket". HTTP is encapsulated within TCP/IP. The ProtocolType
enumeration refers to the transport protocol.
From MSDN on the ProtocolType enumeration,
IP Internet Protocol.
IPv6HopByHopOptions IPv6 Hop by Hop Options header.
Icmp Internet Control Message Protocol.
Igmp Internet Group Management Protocol.
Ggp Gateway To Gateway Protocol.
IPv4 Internet Protocol version 4.
Tcp Transmission Control Protocol.
Pup PARC Universal Packet Protocol.
Udp User Datagram Protocol.
Idp Internet Datagram Protocol.
IPv6 Internet Protocol version 6 (IPv6).
IPv6RoutingHeader IPv6 Routing header.
IPv6FragmentHeader IPv6 Fragment header.
IPSecEncapsulatingSecurityPayload IPv6 Encapsulating Security Payload header.
IPSecAuthenticationHeader IPv6 Authentication header. For details, see RFC 2292 section 2.2.1, available at http://www.ietf.org.
IcmpV6 Internet Control Message Protocol for IPv6.
IPv6NoNextHeader IPv6 No next header.
IPv6DestinationOptions IPv6 Destination Options header.
ND Net Disk Protocol (unofficial).
Raw Raw IP packet protocol.
Unspecified Unspecified protocol.
Ipx Internet Packet Exchange Protocol.
Spx Sequenced Packet Exchange protocol.
SpxII Sequenced Packet Exchange version 2 protocol.
Unknown Unknown protocol.
Look http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/7be22396-0f2a-4138-b47a-09d93894185b The first post shows how to send some bytes through a HTTP-Request. Adapted for your use:
byte[] data;
// ...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(server);
request.ContentType = "application/octet-stream";
request.Method = "POST"; // I think, your data is too big for GET
request.ContentLength = data.Length;
try {
Stream postStream = request.GetRequestStream();
postStream.Write(data, 0, data.Length);
postStream.Close();
} catch(Exception ex) {
throw new Exception(ex.Message);
}
精彩评论