cleaned all trailing white space from source files.
[sdk] / samples / net / SocketTx / socketTX.ec
1 import "ecere"
2
3 // We'll use TCP/IP port 5623 for this sample
4 define samplePort = 5623;
5
6 // We will use this simple structure for our messages
7 struct SamplePacket
8 {
9    int stringLen;
10    // stringLen + 1 bytes are actually used (variable size depending on string)
11    char string[1];
12 };
13
14 // We don't really need anything special in this class here, we could simply use Socket directly
15 class SampleSocket : Socket
16 {
17
18 }
19
20 SampleSocket socket { };
21
22 class TXApp : GuiApplication
23 {
24    void Main()
25    {
26       if(socket.Connect("localhost", samplePort))
27       {
28          // We build up a SamplePacket here with our message
29          String string = "Hello !";
30          int len = strlen(string);
31          int size = sizeof(SamplePacket) + len;
32          SamplePacket * packet = (SamplePacket *)new byte[size];
33          packet->stringLen = len;
34          memcpy(packet->string, string, len+1);
35
36          socket.Send(packet, size);
37
38          // Make sure to free memory allocated with 'new'
39          delete packet;
40       }
41    }
42 }