Simply:
I’m trying to make a program that sends some data over a TCP connection to a server, but i am having some trouble with running it repeatedly. After going through the script once, the next time it should run, it stops mid-script.
More detailed:
The funtion to be run is part of main(), but only runs once an external interrupt is called, which increases a variable, allowing the TCP script to run. The problem is, after having gone through the script, it appears as if the socket has become invalid, as the second time I run it, by external interrupt, the program stops at a while loop that i have trouble understanding, the (!socket_established… loop after the tcp_open command. I’m hoping a kind soul will help with this, as i’m kinda lost
The script:
#define TCPCONFIG 1
#define SERVERIP “192.168.193.241”
#use “dcrtcp.lib”
#define PORT 23
tcp_Socket socket;
longword destIP;
int checkup;
void my_isr0();
void main()
{
checkup = 0;
WrPortI(PEDDR, &PEDDRShadow, 0x00);
#if SEPARATE_INST_DATA && (_RK_FIXED_VECTORS)
interrupt_vector ext0_intvec my_isr0;
#else
SetVectExtern3000(0, my_isr0);
SetVectExtern3000(0, GetVectExtern3000(0));
#endif
WrPortI(I0CR, &I0CRShadow, 0x05);
printf("Standby for connection…
");
while(1)
{
if (checkup >= 1)
{
sock_init();
printf("Sock_Init passed
");
destIP = inet_addr(SERVERIP);
tcp_open(&socket,0,destIP,PORT,NULL);
printf("Tcp_Open passed
");
while(!sock_established(&socket) && sock_bytesready(&socket)==-1)
tcp_tick(NULL);
printf("Connection made...
");
sock_write(&socket,"Sent",4);
printf("Connection closed...
");
printf("Trigger set to rising and falling
");
WrPortI(I0CR, &I0CRShadow, 0x05);
checkup =0;
sock_abort(&socket);
}
}
}
interrupt void my_isr0()
{
WrPortI(I0CR, &I0CRShadow, 0x00);
printf("Trigger disabled
");
checkup++;
}