내용으로 건너뛰기
사용자 도구
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
English
현재 위치:
index
»
cublocapp
»
an41006
cublocapp:an41006:index
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== AN41006 - 웹서버 구현 ====== 다음은 모아콘과 이더넷모듈을 사용해서 간단한 웹서버를 구현한 프로그램입니다. <code c> #include "moacon500.h" #include <string.h> void cmain(void) { //Configure the network settings u8 GatewayIP[]={192,168,0,1}; u8 SubnetMask[]={255,255,255,0}; u8 MacAdr[]={0,0,34,53,12,0}; u8 DeviceIp[]={192,168,0,12}; netBegin(GatewayIP, SubnetMask, MacAdr, DeviceIp); //Use socket 0 u8 socket = 0; //Keep track of the connection status u8 currentStatus = 0xFF; u8 lastStatus = 0xFF; while (1) //Run forever { currentStatus = netStatus(socket); if (currentStatus != lastStatus) //If connection status changes { lastStatus = currentStatus; switch(currentStatus) { case SOCK_INIT: //If not listening, start listening printf("Init\r\n"); socketOpen(socket,8080); listen(socket); break; case SOCK_CLOSED: //If closed, start listening printf("Closed\r\n"); socketOpen(socket,8080); MOACON User’s Manual - 208 - listen(socket); break; case SOCK_ESTABLISHED: //If connection establed, respond printf("Established\r\n"); netPrint(socket, "HTTP/1.0 200 OK\r\n"); netPrint(socket, "Content-Type: text\r\n"); char* hello = "Hello from the MOACON"; netPrint(socket, "Content-Length: %d\r\n\r\n", strlen(hello)); netPrint(socket, "%s", hello); break; case SOCK_LISTEN: //If listening, just wait printf("Listening\r\n"); break; case SOCK_CLOSE_WAIT: //If client disconnects, disconnect printf("Closing\r\n"); disConnect(socket); break; default: break; } delay(10); //Wait for 10 milliseconds } } } </code> 웹서버가 준비되면, 디버그창에 다음과 같은 멧세지가 표시됩니다. {{ :cublocapp:an41006:webserver1.png?nolink |}} 브라우저에서 아래와 같이 해당 ip 주소와 8080 포트를 입력하십시오. 브라우저에는 모아콘에서 보낸 문자열이 표시됩니다. {{ :cublocapp:an41006:webserver2.png?nolink |}} 디버그 창에는 웹서버의 상태가 표시되도록 하였습니다. {{ :cublocapp:an41006:webserver3.png?nolink |}} [[cublocapp:index|이전단계로]]
cublocapp/an41006/index.txt
· 마지막으로 수정됨: 2017/10/19 22:49 저자
Comfile Technology
문서 도구
문서 보기
이전 판
역링크
맨 위로