Mercurial
comparison playground/main.c @ 179:8d17f6e6e290
[ThirdParty] Added emsdk bazel rules that can be supported by bazel 9.0.0
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 22 Jan 2026 21:23:17 -0800 |
| parents | 7387eec8e7f8 |
| children |
comparison
equal
deleted
inserted
replaced
| 178:94705b5986b3 | 179:8d17f6e6e290 |
|---|---|
| 1 #include "seobeo/seobeo.h" | 1 int main() |
| 2 | |
| 3 void Test_Echo() | |
| 4 { | 2 { |
| 5 printf("\n=== Test: Multiple Messages ===\n"); | 3 int a = 0; |
| 6 Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("wss://mrjunejune.com/echo"); | 4 a += 1; |
| 7 if (!p_ws) | 5 return a; |
| 8 { | |
| 9 printf("Failed to connect\n"); | |
| 10 return; | |
| 11 } | |
| 12 | |
| 13 const char *messages[] = { | |
| 14 "Message 1", | |
| 15 "Message 2", | |
| 16 "Message 3" | |
| 17 }; | |
| 18 | |
| 19 for (int i = 0; i < 3; i++) | |
| 20 { | |
| 21 printf("Sending: %s\n", messages[i]); | |
| 22 Seobeo_WebSocket_Send_Text(p_ws, messages[i]); | |
| 23 usleep(100000); | |
| 24 } | |
| 25 | |
| 26 printf("Receiving responses...\n"); | |
| 27 int received = 0; | |
| 28 int attempts = 0; | |
| 29 | |
| 30 while (received < 3 && attempts < 200) | |
| 31 { | |
| 32 Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws); | |
| 33 if (p_msg) | |
| 34 { | |
| 35 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT) | |
| 36 { | |
| 37 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data); | |
| 38 received++; | |
| 39 } | |
| 40 Seobeo_WebSocket_Message_Destroy(p_msg); | |
| 41 } | |
| 42 | |
| 43 usleep(10000); | |
| 44 attempts++; | |
| 45 } | |
| 46 printf("Received %d/%d messages\n", received, 3); | |
| 47 Seobeo_WebSocket_Destroy(p_ws); | |
| 48 } | 6 } |
| 49 | |
| 50 void Test_Chat() | |
| 51 { | |
| 52 printf("\n=== Test: Multiple Messages ===\n"); | |
| 53 | |
| 54 Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://127.0.0.1:8080/chat"); | |
| 55 if (!p_ws) | |
| 56 { | |
| 57 printf("Failed to connect\n"); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 const char *messages[] = { | |
| 62 "Message 1", | |
| 63 "Message 2", | |
| 64 "Message 3" | |
| 65 }; | |
| 66 | |
| 67 for (int i = 0; i < 3; i++) | |
| 68 { | |
| 69 printf("Sending: %s\n", messages[i]); | |
| 70 Seobeo_WebSocket_Send_Text(p_ws, messages[i]); | |
| 71 usleep(100000); | |
| 72 } | |
| 73 | |
| 74 printf("Receiving responses...\n"); | |
| 75 int received = 0; | |
| 76 int attempts = 0; | |
| 77 | |
| 78 while (received < 3 && attempts < 200) | |
| 79 { | |
| 80 Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws); | |
| 81 if (p_msg) | |
| 82 { | |
| 83 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT) | |
| 84 { | |
| 85 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data); | |
| 86 received++; | |
| 87 } | |
| 88 Seobeo_WebSocket_Message_Destroy(p_msg); | |
| 89 } | |
| 90 | |
| 91 usleep(10000); | |
| 92 attempts++; | |
| 93 } | |
| 94 printf("Received %d/%d messages\n", received, 3); | |
| 95 Seobeo_WebSocket_Destroy(p_ws); | |
| 96 } | |
| 97 | |
| 98 int main(int argc, char *argv[]) | |
| 99 { | |
| 100 | |
| 101 Test_Echo(); | |
| 102 } |