Created
November 10, 2016 13:29
-
-
Save ChunChunMorning/b3b85482b730a228c076f1a7b93a501c to your computer and use it in GitHub Desktop.
Siv3DのTCPClientで文字列を送受信する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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