mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 09:39:16 +02:00
added communication security layer to refetch unclompleted pakages
This commit is contained in:
parent
9a74c8d1e4
commit
6e7234b544
2 changed files with 36 additions and 21 deletions
|
@ -32,14 +32,15 @@ public class NetworkServer implements Runnable {
|
|||
CanvasActivity.get().sendMotionStopSignal();
|
||||
CanvasActivity.get().refreshBackground();
|
||||
while (true) {
|
||||
byte[] buf = new byte[60030];
|
||||
byte[] buf = new byte[60031];
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
socket.receive(packet);
|
||||
int n = buf[60029];
|
||||
Log.i("receive:", String.valueOf(n));
|
||||
if (n != 0){
|
||||
packets = buf[60030];
|
||||
buffer.put(n, buf);
|
||||
} else if (buffer.size() > 0 ) {
|
||||
} else if (buffer.size() == packets) {
|
||||
try {
|
||||
String path = CanvasActivity.SCREEN_PATH;
|
||||
boolean parts = buffer.size() == (int) buf[0];
|
||||
|
@ -71,8 +72,12 @@ public class NetworkServer implements Runnable {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//compile image and set it
|
||||
buffer.clear();
|
||||
} else {
|
||||
buffer.clear();
|
||||
//compile image and set it
|
||||
CanvasActivity.get().refreshBackground();
|
||||
Log.i("PacketProblem", "Did not receive all packages - refreshing - " + String.valueOf(buffer.size()) + " and " + String.valueOf(packets));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
/* Compile with
|
||||
* gcc networktablet.c -lX11 `pkg-config --cflags --libs gtk+-3.0`
|
||||
* */
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/X.h>
|
||||
#include <cairo.h>
|
||||
#include <cairo-xlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
|
@ -126,17 +125,19 @@ void msleep(int ms){
|
|||
}
|
||||
|
||||
void *send_current_screen(void *arg){
|
||||
while (sending) {
|
||||
msleep(500);
|
||||
}
|
||||
printf("\nsend_thread\n");
|
||||
sending_t *args = (sending_t*) arg;
|
||||
sockaddr_in from = args->from;
|
||||
int slen = args->slen;
|
||||
Display *disp = XOpenDisplay(":0");
|
||||
|
||||
if (sending || !disp) {
|
||||
if (!disp) {
|
||||
return NULL;
|
||||
}
|
||||
printf("\nsend_thread\n");
|
||||
|
||||
msleep(300);
|
||||
sending=1;
|
||||
Window root;
|
||||
cairo_surface_t *surface;
|
||||
|
@ -158,14 +159,21 @@ void *send_current_screen(void *arg){
|
|||
}
|
||||
from.sin_port = htons(GFXTABLET_PORT);
|
||||
int max=60000;
|
||||
char buff[max+30];
|
||||
char buff[max+31];
|
||||
int n=1;
|
||||
fseek(istream, 0, SEEK_END); // seek to end of file
|
||||
long size = ftell(istream); // get current file pointer
|
||||
int packets = size / max + 1;
|
||||
fseek(istream, 0, SEEK_SET); // seek back to beginning of file
|
||||
|
||||
while (fread(buff, sizeof(char), max, istream) != 0) {
|
||||
printf("Send packet to %s:%d\n", inet_ntoa(from.sin_addr), ntohs(from.sin_port));
|
||||
printf("Send packet to %s:%d - %d of %d\n", inet_ntoa(from.sin_addr), ntohs(from.sin_port), n, packets);
|
||||
buff[max +29] = n;
|
||||
buff[max +30] = packets;
|
||||
if (sendto(udp_socket, buff, sizeof(buff), 0, (struct sockaddr*) &from, slen) == -1){
|
||||
die("sendto()");
|
||||
}
|
||||
msleep(10);
|
||||
n++;
|
||||
for (int r = 0; r <= max ; r++){
|
||||
buff[r] = 0;
|
||||
|
@ -218,9 +226,11 @@ int main(void){
|
|||
ev_pkt.pressure = ntohs(ev_pkt.pressure);
|
||||
printf("x: %hu, y: %hu, pressure: %hu\n", ev_pkt.x, ev_pkt.y, ev_pkt.pressure);
|
||||
|
||||
if (ev_pkt.x != 0 && ev_pkt.y != 0) {
|
||||
send_event(device, EV_ABS, ABS_X, ev_pkt.x);
|
||||
send_event(device, EV_ABS, ABS_Y, ev_pkt.y);
|
||||
send_event(device, EV_ABS, ABS_PRESSURE, ev_pkt.pressure);
|
||||
}
|
||||
|
||||
switch (ev_pkt.type) {
|
||||
case EVENT_TYPE_MOTION:
|
||||
|
@ -244,13 +254,13 @@ int main(void){
|
|||
break;
|
||||
}
|
||||
|
||||
if (ev_pkt.pressure == 0 && memcmp(inet_ntoa(sock_t.from.sin_addr), "0.0.0.0", 7) != 0) {
|
||||
if(pthread_create(&screen_send_t, NULL, send_current_screen, &sock_t)) {
|
||||
if (ev_pkt.down == 0 && ev_pkt.pressure == 0 &&
|
||||
memcmp(inet_ntoa(sock_t.from.sin_addr), "0.0.0.0", 7) != 0 &&
|
||||
pthread_create(&screen_send_t, NULL, send_current_screen, &sock_t)) {
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
close(udp_socket);
|
||||
|
||||
printf("Removing network tablet from device list\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue