extern "C" int MAMain() { const char* purl = "http://wap.mopix.se/"; char buffer[45000] = {0}; Handle sock; int size, result; println("HTTP GET test"); println(purl); // maConnect("socket://www.mopix.se:80", &size); //crash test dummy sock = maConnect(purl); printlnf("sock %i", sock); if(sock <= 0) { goto exit; } result = AnimatedConnWait(); printlnf("result %i", result); if(result <= 0) { goto exit; } size = MAUtil::getHttpConLen(sock); printlnf("size %i", size); if(size <= 0) { goto exit; } { result = ConnReadAtLeast(sock, size, sizeof(buffer), buffer); printlnf("read %i", result); if(result <= 0) { goto exit; } maConnClose(sock); buffer[result] = 0; printlnf(buffer); } exit: println("Yeah, we're done."); FREEZE; }
int AnimatedConnWait() { int startTime = maGetMilliSecondCount(); int res; #ifdef ANIMATED int lPos = gPos; int i=0; int screenWidth = EXTENT_X(maGetScrSize()); maSetColor(0); maFillRect(0, lPos, screenWidth - 1, gTextHeight); printlnf("a%i",i++); #endif //ANIMATED while(1) { EVENT event; #ifdef ANIMATED gPos = lPos; maSetColor(0); maFillRect(0, lPos, screenWidth - 1, gTextHeight); printlnf("b%i",i++); #else maWait(0); #endif //ANIMATED if(maGetEvent(&event)) { if(event.type == EVENT_TYPE_CLOSE || (event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0)) { maExit(0); } else if(event.type == EVENT_TYPE_CONN) { res = event.conn.result; break; } } } printlnf("w%i", maGetMilliSecondCount() - startTime); return res; }
int MAMain() { Handle conn; char ping[] = "ping\n"; char buffer[1024]; int res; #ifdef CONPRINT InitConsole(); gConsoleLogging = 1; #endif //println("Socket test"); retry: printlnf("Connecting..."); conn = maConnect("socket://130.237.3.104:6666"); //test DNS resolution res = AnimatedConnWait(); if(res <= 0) { printlnf("err %i", res); goto exit; } /*conn = maConnect("socket://217.25.35.146:81"); //test IP address reading res = AnimatedConnWait(); if(res <= 0) { printlnf("err %i", res); goto exit; }*/ println("Writing..."); maConnWrite(conn, ping, sizeof(ping)); res = AnimatedConnWait(); if(res <= 0) { printlnf("err %i", res); goto exit; } println("Reading..."); res = ConnReadAtLeast(conn, 4, sizeof(buffer), buffer); if(res <= 0) { printlnf("err %i", res); goto exit; } maConnClose(conn); printlnf("Got %i bytes", res); buffer[res] = 0; println(buffer); maUpdateScreen(); exit: println("Press a key"); for(;;) { EVENT event; while(maGetEvent(&event)) { if(event.type == EVENT_TYPE_CLOSE || (event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0)) { maExit(0); } else if(event.type == EVENT_TYPE_KEY_PRESSED) { goto retry; } } maWait(0); } }
int main() { printlnf("0x02 %d\n", 0x02.01); exit(0); }