Update Home
92
Home.md
92
Home.md
@@ -1 +1,91 @@
|
|||||||
Welcome to the Wiki.
|
### Server
|
||||||
|
```cpp
|
||||||
|
#include <ehs/io/socket/TCP.h>
|
||||||
|
#include <ehs/io/Console.h>
|
||||||
|
|
||||||
|
using namespace ehs;
|
||||||
|
|
||||||
|
Vector<TCP *> clients;
|
||||||
|
|
||||||
|
void HandleClients() {
|
||||||
|
for (UInt_64 i = 0; i < clients.Size(); ++i) {
|
||||||
|
Str_8 data(256);
|
||||||
|
|
||||||
|
UInt_64 received = clients[i]->Receive((Byte *)&data[0], data.Size());
|
||||||
|
if (!received)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
data.Resize(received);
|
||||||
|
|
||||||
|
Console::Write_8(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Initialize("Server", "Alpha", {1, 0, 0});
|
||||||
|
|
||||||
|
TCP server;
|
||||||
|
server.Initialize();
|
||||||
|
server.SetBlocking(false);
|
||||||
|
server.Bind("", 1234);
|
||||||
|
Console::Write_8("server started on port 1234");
|
||||||
|
server.Listen();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
TCP *client = server.Accept();
|
||||||
|
if (client) {
|
||||||
|
client->SetBlocking(false);
|
||||||
|
|
||||||
|
clients.Push(client);
|
||||||
|
|
||||||
|
client->SendStr("Successfully connected to server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
Uninitialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Client
|
||||||
|
```cpp
|
||||||
|
#include <ehs/io/socket/TCP.h>
|
||||||
|
#include <ehs/io/socket/DNS.h>
|
||||||
|
#include <ehs/io/Console.h>
|
||||||
|
|
||||||
|
using namespace ehs;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Initialize("Client", "Alpha", {1, 0, 0});
|
||||||
|
|
||||||
|
TCP client(IP::V4);
|
||||||
|
client.Initialize();
|
||||||
|
client.SetBlocking(false);
|
||||||
|
client.Connect("127.0.0.1", 1234);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Str_8 data(256);
|
||||||
|
|
||||||
|
UInt_64 received = client.Receive((Byte*)&data[0], data.Size());
|
||||||
|
|
||||||
|
if (received)
|
||||||
|
{
|
||||||
|
data.Resize(received);
|
||||||
|
|
||||||
|
Console::Write_8(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Str_8 msg = Console::Read_8();
|
||||||
|
|
||||||
|
client.SendStr(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
Uninitialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user