不管你的服务器或客户机使用哪种技术,如果他们可以使用某种标准的“协议”彼此通信。在
有很多方法可以用来通信双方(客户机和服务器),比如套接字、xml、json等等,它们只需要相互理解就可以了。在
在您的特定案例中,我建议在服务器上构建REST或restfulapi(https://flask-restful.readthedocs.org/en/0.3.3/),在客户机上构建REST客户机库。在
有很多方法和库可以从C调用REST API:
内置方法将使用HttpWebRequest,如您在link上看到的:private async Task FetchWeatherAsync (string url)
{
// Create an HTTP web request using the URL:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (new Uri (url));
request.ContentType = "application/json";
request.Method = "GET";
// Send the request to the server and wait for the response:
using (WebResponse response = await request.GetResponseAsync ())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStr