일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 전기차충전기
- 전기차충전
- 펌웨어
- AWS
- dynamodb
- 안드로이드
- OCPP
- raspberry
- 홈어시스턴트
- esp8266
- Android
- 완속충전기
- 파이썬
- YMODEM
- 서버리스
- 에버온
- 라즈베리파이
- lambda
- 급속충전기
- homeassistant
- thread
- STM32
- IOT Core
- 보안
- 디자인패턴
- flask
- 플라스크
- everon
- 전기차
- 충전기
Archives
- Today
- Total
Louie NRT Story
[RaspberryPi] Chatting Program using Shared Memory Flag 본문
에너지
[RaspberryPi] Chatting Program using Shared Memory Flag
hyeok0724.kim@gmail.com 2019. 5. 6. 21:26반응형
[EcoServerBySharedMemory.c]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#define SHARED_MEMORY_KEY 1111
#define MEMORY_SIZE 1024
#define READ_CLIENT_FLAG 0
#define READ_SERVER_FLAG 1
#define PRINT_CLIENT_FLAG 2
int main()
{
int shmid;
char *buffer;
char *string;
//make space that shared-memory
shmid = shmget((key_t)SHARED_MEMORY_KEY, MEMORY_SIZE, 0666|IPC_CREAT);
if(shmid == -1)
{
perror("shmget failed: ");
exit(0);
}
//attach shared memory
buffer = shmat(shmid, (void *)0, 0);
if(buffer == (void *)-1)
{
perror("shmat failed:");
exit(0);
}
string = buffer + 1;
buffer[0] = READ_CLIENT_FLAG;
while(1)
{
if(buffer[0] == READ_SERVER_FLAG)
{
puts(string);
strcat(string, "by server");
buffer[0] = PRINT_CLIENT_FLAG;
}
sleep(1);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
[EcoClientBySharedMemory.c]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#define SHARED_MEMORY_KEY 1111
#define MEMORY_SIZE 1024
#define READ_CLIENT_FLAG 0
#define READ_SERVER_FLAG 1
#define PRINT_CLIENT_FLAG 2
int main()
{
int shmid;
char *buffer;
char *string;
//make space that shared-memory
shmid = shmget((key_t)SHARED_MEMORY_KEY, MEMORY_SIZE, 0666 | IPC_CREAT);
if(shmid == -1)
{
perror("shmget failed: ");
exit(0);
}
//attach shared memory
buffer = shmat(shmid, NULL, 0);
if(buffer == (void *)-1)
{
perror("shmat failed: ");
exit(0);
}
buffer[0] = READ_CLIENT_FLAG;
string = buffer + 1;
while(1)
{
if(buffer[0] == READ_CLIENT_FLAG)
{
printf("message : ");
scanf("%s", string);
buffer[0] = READ_SERVER_FLAG;
}
else if(buffer[0] == PRINT_CLIENT_FLAG)
{
puts(string);
buffer[0] = READ_CLIENT_FLAG;
}
sleep(1);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
반응형
'에너지' 카테고리의 다른 글
[Raspberry Pi] Install Raspbian on Raspberry Pi (0) | 2019.10.23 |
---|---|
[RaspberryPi] Thread & Shared Memory & USB Serial Data (0) | 2019.05.06 |
[RasbperryPi] Shared Memory Queue (0) | 2019.05.06 |
[RaspberryPi] Controll LED (0) | 2019.05.06 |
[RaspberryPI] Remote control Car And Camera (0) | 2019.01.20 |
Comments