开发者

Stream Data using HTTP using C#

Currently I am sending data from client using Socket over TCP. I need this t开发者_如何转开发o be done over HTTP, so that the load balancing can be done at the server side. Any help would be appreciated. I have added a bit of my code, where I am send the data over TCP.

IPEndPoint iep = new IPEndPoint(IPAddress.Parse(textBox1.Text),Convert.ToInt32(textBox2.Text));
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sock.Connect(iep);


You basically do a POST to the server every time you want put something there and you do a GET when you want to see if there were any changes.

I haven't tested this code, but it should give you a general idea:

public void SendData(byte[] data)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.host.com:80/");

    request.Method = "POST";
    request.ContentType="application/x-www-form-urlencoded";
    request.ContentLength = data.Length;

    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
    {
        writer.Write(data, 0, data.Length);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜