Mercurial
annotate playground/main.c @ 145:c1eab8c0b0f9
[MrJuneJune] Small improvement UX and tests passes now.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 09 Jan 2026 13:42:35 -0800 |
| parents | 893d87124d16 |
| children | 6de849867459 7387eec8e7f8 |
| rev | line source |
|---|---|
| 142 | 1 #include "seobeo/seobeo.h" |
| 2 | |
| 3 void Test_Echo() | |
| 4 { | |
| 5 printf("\n=== Test: Multiple Messages ===\n"); | |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
6 |
| 142 | 7 // Seobeo_Client_Request *foo = Seobeo_Client_Request_Create("http://mrjunejune.com/echo"); |
| 8 // Seobeo_Client_Request_Add_Header_Array(foo, "Upgrade: websocket"); | |
| 9 // Seobeo_Client_Request_Add_Header_Array(foo, "Connection: Upgrade"); | |
| 10 // Seobeo_Client_Request_Add_Header_Array(foo, "Sec-WebSocket-Key: asbc3e12bA"); | |
| 11 // Seobeo_Client_Request_Add_Header_Array(foo, "Sec-WebSocket-Version: 13"); | |
| 12 // Seobeo_Client_Response *foo2 = Seobeo_Client_Request_Execute(foo); | |
| 13 // printf("June: %s\n", foo2->body); | |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
14 |
| 142 | 15 |
| 16 Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://mrjunejune.com/echo"); | |
| 17 // Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://localhost:6969/echo"); | |
| 18 if (!p_ws) | |
| 19 { | |
| 20 printf("Failed to connect\n"); | |
| 21 return; | |
| 22 } | |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
23 |
| 142 | 24 const char *messages[] = { |
| 25 "Message 1", | |
| 26 "Message 2", | |
| 27 "Message 3" | |
| 28 }; | |
| 29 | |
| 30 for (int i = 0; i < 3; i++) | |
| 31 { | |
| 32 printf("Sending: %s\n", messages[i]); | |
| 33 Seobeo_WebSocket_Send_Text(p_ws, messages[i]); | |
| 34 usleep(100000); | |
| 35 } | |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
36 |
| 142 | 37 printf("Receiving responses...\n"); |
| 38 int received = 0; | |
| 39 int attempts = 0; | |
| 40 | |
| 41 while (received < 3 && attempts < 200) | |
| 42 { | |
| 43 Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws); | |
| 44 if (p_msg) | |
| 45 { | |
| 46 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT) | |
| 47 { | |
| 48 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data); | |
| 49 received++; | |
| 50 } | |
| 51 Seobeo_WebSocket_Message_Destroy(p_msg); | |
| 126 | 52 } |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
53 |
| 142 | 54 usleep(10000); |
| 55 attempts++; | |
| 56 } | |
| 57 printf("Received %d/%d messages\n", received, 3); | |
| 58 Seobeo_WebSocket_Destroy(p_ws); | |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 } |
| 142 | 60 |
| 61 void Test_Chat() | |
| 62 { | |
| 63 printf("\n=== Test: Multiple Messages ===\n"); | |
| 64 | |
| 65 Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://127.0.0.1:8080/chat"); | |
| 66 if (!p_ws) | |
| 67 { | |
| 68 printf("Failed to connect\n"); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 const char *messages[] = { | |
| 73 "Message 1", | |
| 74 "Message 2", | |
| 75 "Message 3" | |
| 76 }; | |
| 77 | |
| 78 for (int i = 0; i < 3; i++) | |
| 79 { | |
| 80 printf("Sending: %s\n", messages[i]); | |
| 81 Seobeo_WebSocket_Send_Text(p_ws, messages[i]); | |
| 82 usleep(100000); | |
| 83 } | |
| 84 | |
| 85 printf("Receiving responses...\n"); | |
| 86 int received = 0; | |
| 87 int attempts = 0; | |
| 88 | |
| 89 while (received < 3 && attempts < 200) | |
| 90 { | |
| 91 Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws); | |
| 92 if (p_msg) | |
| 93 { | |
| 94 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT) | |
| 95 { | |
| 96 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data); | |
| 97 received++; | |
| 98 } | |
| 99 Seobeo_WebSocket_Message_Destroy(p_msg); | |
| 100 } | |
| 101 | |
| 102 usleep(10000); | |
| 103 attempts++; | |
| 104 } | |
| 105 printf("Received %d/%d messages\n", received, 3); | |
| 106 Seobeo_WebSocket_Destroy(p_ws); | |
| 107 } | |
| 108 | |
| 109 int main(int argc, char *argv[]) | |
| 110 { | |
| 111 | |
| 112 Test_Echo(); | |
| 113 } |