Skip to content

Instantly share code, notes, and snippets.

@ChunChunMorning
Created November 10, 2016 13:29
Show Gist options
  • Save ChunChunMorning/b3b85482b730a228c076f1a7b93a501c to your computer and use it in GitHub Desktop.
Save ChunChunMorning/b3b85482b730a228c076f1a7b93a501c to your computer and use it in GitHub Desktop.
Siv3DのTCPClientで文字列を送受信する
# include <Siv3D.hpp>
void Main()
{
TCPClient client;
client.connect(IPv4::localhost(), 50000);
std::string message;
while (System::Update())
{
if (client.isConnected())
{
const auto str = ToUTF8(L"Hello\n");
client.send(str.data(), sizeof(char) * str.length());
Println(L"Send: Hello");
for (;;)
{
char character;
if (!client.read(character))
break;
if (character == '\n')
{
Println(L"Receive: ", FromUTF8(message));
message.clear();
}
else
{
message.push_back(character);
}
}
}
if (client.hasError())
{
client.disconnect();
client.connect(IPv4::localhost(), 50000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment