0

我需要的是一个解决方案,它可以让我(和我的编程竞赛团队成员)在 Windows 下以最简单的方式在 C++ 中使用 TCP/IP。某些任务可能需要与服务器进行完全同步的文本通信。最好的选择是一些 DOS 命令或程序,它将重定向应用程序的进/出通信并通过 TCP 发送/接收它,例如 Linux netcat:

> cool_proxy 123.122.121.43 1234 abc.exe

在程序内部:

int query;
cin >> query;
cout << "The answer is " << (query+123);

但是,Windows netcat 似乎错过了该功能......如果这不可能,其他一些简单的选项可能会有所帮助:

Some_cool_sockect scs("123.122.121.42:1234");
scs.connect();
int query;
scs >> query;
scs << "The answer is " << (query+123);

它不需要达到高性能;只是简单的、完全同步的半双工 TCP。我可以在 C# 中非常流利地处理 TCP,所以我可以编写某种代理,但也许这个东西已经存在 :)

4

1 回答 1

0

You may want to have a look at a library like POCO. In the namespace Poco::Net there are several classes which allow you to create a client/server.

As this library is open source you can have a look at it and see how these classes create sockets etc.

Googling for "windows socket c++" also brought this example: This will also give necessary basics, however I do not know if this example is up to date so it might not work with current Windows versions.

于 2012-03-14T17:17:16.040 回答