Arduino Mini Atmega168 udp problem ping

First to explain my goal I'm trying to control my robot to go forward,back,right,left and stop with UDP(User Datagram Protocol) protocol

I'm using

  • Arduino Mini Atmega168
  • Lan ENC28J60
  • Router Tp-Link 150Mbps Wireless N Nano
  • Motor Driver L293D
  • and Application in C# with buttons forward,back,left,right and stop

arduino ip address is 192.168.178.60 I'm pinging that address without problem but if I try to click faster on the buttons to control or click any button and leave it more time example to go forward it blocks or to left it blocks and I must restart arduino to get my ping back.The main problem is why I lose my conecction so fast.

Here is my code

#include "EtherShield.h"
//8 or 16 bit integer
uint8_t mymac[6] = {0xCF,0x70,0x7C,0xE4,0x8A,0xB8};
uint8_t myip[4] = {192,168,178,60};
uint16_t MYWWWPORT = 80;

#define BUFFER_SIZE 750

static uint8_t buf[BUFFER_SIZE+1];

EtherShield es=EtherShield();

uint16_t dat_p;

///----------------------------------------------------------
void setup(){

Setup_Pins();
es.ES_enc28j60Init(mymac);
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);

}

///----------------------------------------------------------

void loop(){

// read packet, handle ping and wait for a tcp packet:
buf[IP_PROTO_P]=0;
dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));

if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
Motor_Control();
buf[IP_PROTO_P]=0;
}
}

//----------------------------------------------------------

void Setup_Pins(){

pinMode(4, OUTPUT); digitalWrite(4, 0);//lev
pinMode(5, OUTPUT); digitalWrite(5, 0);//lev
pinMode(6, OUTPUT); digitalWrite(6, 0);//desen
pinMode(7, OUTPUT); digitalWrite(7, 0);//desen

}

///----------------------------------------------------------

void Motor_Control(){

char* recv = (char*)buf + 42;

// forward

if (strncmp(recv, "forward", 7) == 0) {
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 1);
}

//left

if (strncmp(recv, "left", 4) == 0) {
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 1);
}

//stop

if (strncmp(recv, "stop", 4) == 0) {
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
}

//right

if (strncmp(recv, "right", 5) == 0) {
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 0);
}

//back

if (strncmp(recv, "back", 4) == 0) {
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 1);
digitalWrite(7, 0);
}
delay(6);

}

///----------------------------------------------------------
arduino