fir
2024-02-07 23:18:53 UTC
i slightly thinked on how socket programing shpuld look
like in c (in pseudocode) maybe something like this
(a bit in pseudocode)
main() //client
{
int id = connect("adress", port);
for(int i=0; i<100; i++) // repeat 100x 10ms wait on connection done
{
if(connected(id)) goto connected:
sleep(10);
}
non_connected:
exit("non connected");
connected:
for(;;)
{
int n = received_packets(id)
for(int i=0; i<n;i++)
{
char* data = recv(id);
printf("%s", data);
}
sleep(10);
}
}
and encountered a case where you would like to get
else clausule after for in c (not first time)
it is becouse if you get something to appear in loop
if it appear you can break and continue but if it will not
you will ned to do something else
and without this else clause you must use gotos, which is not
a big problem but it overally shows that this for may need
an else
(not to say its good idea as for else yet with break dont look to much
optimal probably but its sorta interesting notice i think
like in c (in pseudocode) maybe something like this
(a bit in pseudocode)
main() //client
{
int id = connect("adress", port);
for(int i=0; i<100; i++) // repeat 100x 10ms wait on connection done
{
if(connected(id)) goto connected:
sleep(10);
}
non_connected:
exit("non connected");
connected:
for(;;)
{
int n = received_packets(id)
for(int i=0; i<n;i++)
{
char* data = recv(id);
printf("%s", data);
}
sleep(10);
}
}
and encountered a case where you would like to get
else clausule after for in c (not first time)
it is becouse if you get something to appear in loop
if it appear you can break and continue but if it will not
you will ned to do something else
and without this else clause you must use gotos, which is not
a big problem but it overally shows that this for may need
an else
(not to say its good idea as for else yet with break dont look to much
optimal probably but its sorta interesting notice i think