Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/iomsg.h>
- #include <sys/neutrino.h>
- #include "connection_id.h"
- //...
- //Прочие заголовки.
- //...
- #define MSG_PREFIX "delay 2 calc "
- static const size_t MSG_PREFIX_LENGTH = sizeof MSG_PREFIX / sizeof(char) - 1;
- int OnSendClicked(PtWidget_t* widget, ApInfo_t* apinfo, PtCallbackInfo_t* cbinfo) {
- char msg[256] = MSG_PREFIX;
- char response[40];
- char* input;
- size_t msgSize;
- //Получаем текст, введенный в InputTextBox.
- PtGetResource(ABW_InputTextBox, Pt_ARG_TEXT_STRING, &input, 0);
- //Приписываем его к сообщению.
- strncpy(msg + MSG_PREFIX_LENGTH, input, sizeof msg / sizeof(char) - MSG_PREFIX_LENGTH);
- //Вычисляем размер сообщения.
- msgSize = MSG_PREFIX_LENGTH + (strlen(input) + 1) * sizeof(char);
- //Отправляем на сервер.
- if (MsgSend(connectionId, msg, msgSize, response, sizeof response) == -1) {
- fputs("Cannot send a message\n", stderr);
- exit(1);
- }
- //Выводим ответ сервера в OutputTextBox.
- PtSetResource(ABW_OutputTextBox, Pt_ARG_TEXT_STRING, response, strlen(response) * sizeof(char));
- return Pt_CONTINUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement