当前位置: 首页>>代码示例>>C++>>正文


C++ EthernetClient::write方法代码示例

本文整理汇总了C++中EthernetClient::write方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetClient::write方法的具体用法?C++ EthernetClient::write怎么用?C++ EthernetClient::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EthernetClient的用法示例。


在下文中一共展示了EthernetClient::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: network_send

size_t ArduinoiDigiInterfaceClass::network_send(idigi_network_handle_t *handle, char *buffer, size_t length)
{
  EthernetClient *client = (EthernetClient *) handle;
  AR_DEBUG_PRINTF("network_send: len = %d\r\n", length);
  size_t sent = client->write((const uint8_t *) buffer, length);
  return sent;
}
开发者ID:GUBotDev,项目名称:idigi-arduino-connector,代码行数:7,代码来源:ArduinoiDigiInterface.cpp

示例2: printP

static void printP(EthernetClient client, const prog_uchar *str) 
{
    uint8_t pgmChar;
    while(pgmChar = pgm_read_byte(str++))
    {
      client.write(pgmChar);
    }
}
开发者ID:ArduinoBR,项目名称:EthernetSup,代码行数:8,代码来源:EthernetSup.cpp

示例3: flush_sendbuf

static int flush_sendbuf(EthernetClient & client)
{
	int ret = 0;
	if (sendbufptr > sendbuf)
	{
		ret = client.write((uint8_t*)sendbuf, sendbufptr-sendbuf);
		setup_sendbuf();
	}
	return ret;
}
开发者ID:egisz,项目名称:sprinklers_pi,代码行数:10,代码来源:web.cpp

示例4: GetVals

Weather::ReturnVals Weather::GetVals(const char * key, uint32_t zip, const char * pws, bool usePws) const
{
	ReturnVals vals = {0};
	EthernetClient client;
	if (client.connect(m_wundergroundAPIHost, 80))
	{
		char getstring[255];
		trace(F("Connected\n"));
		if (usePws)
			snprintf(getstring, sizeof(getstring), "GET http://%s/api/%s/yesterday/conditions/q/pws:%s.json HTTP/1.1\r\n",m_wundergroundAPIHost, key, pws);
		else
			snprintf(getstring, sizeof(getstring), "GET http://%s/api/%s/yesterday/conditions/q/%ld.json HTTP/1.1\r\n",m_wundergroundAPIHost, key, (long) zip);

		//trace("GetString:%s\n",getstring);
		client.write((uint8_t*) getstring, strlen(getstring));
		
		//send host header
		snprintf(getstring, sizeof(getstring), "Host: %s\r\nConnection: close\r\n\r\n",m_wundergroundAPIHost);
		//trace("GetString:%s\n",getstring);
		client.write((uint8_t*) getstring, strlen(getstring));

		ParseResponse(client, &vals);
		vals.resolvedIP=client.GetIpAddress();

		client.stop();
		if (!vals.valid)
		{
			if (vals.keynotfound)
				trace("Invalid WUnderground Key\n");
			else
				trace("Bad WUnderground Response\n");
		}
	}
	else
	{
		trace(F("connection failed\n"));
		client.stop();
	}
	return vals;
}
开发者ID:gerrypower,项目名称:sprinklers_pi,代码行数:40,代码来源:Weather.cpp

示例5: SendFrame

void SendFrame(uint8_t fr_nr)
{
	// init frame to send
	memcpy_P(&frame[0], &ec_frames[fr_nr], sizeof(modbus_head_t));
	CalculateCRC(6);  // add crc bytes to the end of frame starting form byte position 6
#if _DEBUG_>1
	Serial.print(F("Sending EnergyCam frame:"));
	for (byte i=0; i<8; i++) {
		Serial.print(' ');
		byte tmp = frame[i];
		if ( tmp<16 ) Serial.print(0);
		Serial.print(tmp, HEX);
	}
	Serial.println();
#endif
	while ( (millis()-startDelay)<2 ) WDG_RST;	// wait for frame delay
	// prepare to send
#ifdef USE_RS485
	RS485_ENABLE_TX;
	delayMicroseconds(100);
	// write RS485 header
	Serial1.write(EC_ID);
	Serial1.write(0xFF^EC_ID);
	Serial1.write(frame, 8);
	// prepare to receive the answer
	Serial1.flush();	// wait till all data was sent
	delayMicroseconds(300);
	RS485_ENABLE_RX;
#else
	ec_client.write((byte)0);	// wake-up from sleep mode
	delay(2);	// frame delay
	//frameSize = 8;
	ec_client.write(frame, 8);
	// wait till last byte was sent
	//	delayMicroseconds(frameDelay);
	delay(2);	// frame delay
#endif
	Modbus_WaitForReply();	// wait one second long till complete reply frame is received
//	return error_code;
}
开发者ID:stevstrong,项目名称:HomeServer,代码行数:40,代码来源:energy_cam.cpp

示例6: api_call_http_register_self

void api_call_http_register_self(byte amsg_server[]) {


	char path[ 30 ];
	char host[ 30 ];
	strcpy_P(path, msg_server_path);
	strcpy_P(host, msg_server_host);

	EthernetClient client;


	Serial.print("HTTP opening connection to ");
	Serial.println(host);
	/*
	if (!ether.dnsLookup(website))
		  Serial.println("DNS failed");
	else
		  Serial.println("DNS resolution done");
	ether.printIp("SRV IP:\t", ether.hisip);
	*/

	if (!client.connect(amsg_server, pgm_read_word(&msg_server_port))) {
		Serial.println("HTTP failed");
		return;
	}

	char d;
	String netbuf = "GET ";
	netbuf += path;
	netbuf += " HTTP/1.0\nHost: ";
	netbuf += host;
	netbuf += "\nConnection: close\n\n\n";

	Serial.print("HTTP connected to ... ");

	char sockbuf[ netbuf.length() ];
	netbuf.toCharArray(sockbuf, netbuf.length());
	client.write(sockbuf);
	delay(100);
	while(client.connected()) {
		while(client.available())   {
			d = client.read();
			if (d == '\n')
				Serial.print("\r\n");
			else
				Serial.print(d);
		}
	}	  
	client.stop();
	Serial.println();
}
开发者ID:markkimsal,项目名称:homesecurity,代码行数:51,代码来源:api_call_http.cpp

示例7: task

void ModbusIP::task() {
    EthernetClient client = _server.available();

    if (client) {
        if (client.connected()) {
            int i = 0;
            while (client.available()){
                _MBAP[i] = client.read();
                i++;
                if (i==7) break;  //MBAP length has 7 bytes size
            }
            _len = _MBAP[4] << 8 | _MBAP[5];
            _len--;  // Do not count with last byte from MBAP

            if (_MBAP[2] !=0 || _MBAP[3] !=0) return;   //Not a MODBUSIP packet
            if (_len > MODBUSIP_MAXFRAME) return;      //Length is over MODBUSIP_MAXFRAME

            _frame = (byte*) malloc(_len);
            i = 0;
            while (client.available()){
                _frame[i] = client.read();
                i++;
                if (i==_len) break;
            }

            this->receivePDU(_frame);
            if (_reply != MB_REPLY_OFF) {
                //MBAP
                _MBAP[4] = (_len+1) >> 8;     //_len+1 for last byte from MBAP
                _MBAP[5] = (_len+1) & 0x00FF;

                byte sendbuffer[7 + _len];

                for (i = 0 ; i < 7 ; i++) {
                    sendbuffer[i] = _MBAP[i];
                }
                //PDU Frame
                for (i = 0 ; i < _len ; i++) {
                    sendbuffer[i+7] = _frame[i];
                }
                client.write(sendbuffer, _len + 7);
            }

#ifndef TCP_KEEP_ALIVE
            client.stop();
#endif
            free(_frame);
            _len = 0;
        }
开发者ID:EagleSmith,项目名称:modbus-arduino,代码行数:49,代码来源:ModbusIP.cpp

示例8: ServeFile

static void ServeFile(FILE * stream_file, const char * fname, SdFile & theFile, EthernetClient & client)
{
	freeMemory();
	const char * ext;
	for (ext=fname + strlen(fname); ext>fname; ext--)
		if (*ext == '.')
		{
			ext++;
			break;
		}
	if (ext > fname)
	{
		if (strcmp(ext, "jpg") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/jpeg");
		else if (strcmp(ext, "gif") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/gif");
		else if (strcmp(ext, "css") == 0)
			ServeHeader(stream_file, 200, "OK", true, "text/css");
		else if (strcmp(ext, "js") == 0)
			ServeHeader(stream_file, 200, "OK", true, "application/javascript");
		else if (strcmp(ext, "ico") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/x-icon");
		else
			ServeHeader(stream_file, 200, "OK", true);
	}
	else
		ServeHeader(stream_file, 200, "OK", true);


#ifdef ARDUINO
	flush_sendbuf(client);
#else
	fflush(stream_file);
#endif
	while (theFile.available())
	{
		int bytes = theFile.read(sendbuf, 512);
		if (bytes <= 0)
			break;
		client.write((uint8_t*) sendbuf, bytes);
	}
}
开发者ID:egisz,项目名称:sprinklers_pi,代码行数:42,代码来源:web.cpp

示例9: networkManage

void networkManage() {
	uint16_t size;

	if (sendClient.available()) {
//		int size = sendClient.read((uint8_t *) buf2, BUFFER_SIZE);
		size = readHttpFrame(sendClient);
#ifdef HMAC
		if (!isTimeReady()) {
			uint16_t endPos = strstrpos_P((char *) buf, DOUBLE_ENDL);
			receiveTime((char *) &buf[endPos + 4]);
		}
#endif
	}

#ifdef HMAC
	if (!isTimeReady() && sendClient.status() == SnSR::CLOSED && (lastFailTime == 0 || millis() - lastFailTime > dateFailRetryWait)) {
		if (sendClient.connect(NotifyDstIp, notifyDstPort)) {
			int len = clientBuildTimeQuery((char *) buf);
			sendClient.write(buf, len);
		} else {
			lastFailTime = millis();
			sendClient.stop();
		}
	}
#endif

	if (!sendClient.connected()) {
		sendClient.stop();
	}

	if (notification != 0 && sendClient.status() == SnSR::CLOSED) {
		// there is a notif and we are not handling another one
		if (lastFailTime == 0 || millis() - lastFailTime > notifFailRetryWait) {
			if (sendClient.connect(NotifyDstIp, notifyDstPort)) {
				int len = clientBuildNextQuery((char *) buf);
				sendClient.write(buf, len);
			} else {
				lastFailTime = millis();
				sendClient.stop();
			}
		}
	}

	EthernetClient client = server.available();
    if (client) {
        while (client.connected()) {
            if (client.available()) {
                size = readHttpFrame(client);

                if (size > 0) {
                    buf[size] = 0;
                    size = handleWebRequest((char *) buf, 0, size);
                    buf[size] = 0;
                    client.println((const char *) buf);
                }

                delay(1);
                client.stop();
            }
        }
    }
	if (needReboot) {
		resetFunc();
	}
}
开发者ID:housecream,项目名称:restmcu,代码行数:65,代码来源:network-w5100.cpp

示例10: runExternalCommandsPersistent

void runExternalCommandsPersistent(EthernetServer* _server, systemState* _state) 
{
	// local variables
	int i, buffer_ptr;
	int room, radiatorState, automaticMode;
	float temperature;
	int commandError = 0;
	
	
	EthernetClient client = _server->available(); // is non-blocking
	if(client.available() > 2)
	{
		#ifdef DEBUG
		Serial.println("Connection established");
		Serial.print("Available: ");
		Serial.println(client.available());
		#endif
		
		char buffer[32];
		
		// read command field
		if( readParam(buffer, 3, client) < 0 ) {commandError = 1; goto errorHandler;}
		
		// switch case on commands
		if(strcmp(buffer, "STM") == 0) // set temperature
		{
			#ifdef DEBUG
			Serial.println("Set temperature command received");
			#endif
			
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);
			
			// read second param: temperature (format xx.y)
			if( readParam(buffer, 4, client) < 0 ) {commandError = 1; goto errorHandler;}
			temperature = atof(buffer);
			
			_state->desiredTemp[room] = temperature;
			
			client.write((unsigned char*)"STM", 3);
			client.write((unsigned char*)"OOK", 3);
		}
		else if(strcmp(buffer, "RTM") == 0) // read temperature
		{
			#ifdef DEBUG
			Serial.println("Read temperature command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			
			room = atoi(buffer);
			
			temperature = _state->actualTemp[room];
			//buffer_ptr = sprintf(buffer, "%4.1f", temperature);
			ttoa(buffer, temperature);
			
			client.write((unsigned char*)"RTM", 3);
			client.write((unsigned char*)"OOK", 3);
			client.write((unsigned char*)buffer, 4);
		}
		else if(strcmp(buffer, "SRD") == 0) // set radiator
		{
			#ifdef DEBUG
			Serial.println("Set radiator command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);
			
			// read second param: radiator state (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			radiatorState = atoi(buffer);
			
			_state->radiatorState[room] = radiatorState;
			digitalWrite(radiatorPinByRoom(room), (radiatorState == 1) ? LOW : HIGH);
			
			// set zone valve
			int someoneIsOn = 0;
			for(room = 0; room < 6; room++) 
			{
				if(_state->radiatorState[room] == ON) someoneIsOn = 1;
			}
			digitalWrite(ZONE_VALVE_NO1, someoneIsOn ? LOW : HIGH);
			
			client.write((unsigned char*)"SRD", 3);
			client.write((unsigned char*)"OOK", 3);
		}
		else if(strcmp(buffer, "RRD") == 0) // read radiator
		{
			#ifdef DEBUG
			Serial.println("Read radiator command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);

			radiatorState = _state->radiatorState[room];
			sprintf(buffer, "%d", radiatorState);
			
//.........这里部分代码省略.........
开发者ID:RncLsn,项目名称:tcs,代码行数:101,代码来源:ExternalCommandsPersistent.cpp

示例11: api_call_http

void api_call_http(byte amsg_server[], char body[]) {

	char path[ 30 ];
	char host[ 30 ];
	strcpy_P(path, msg_server_path);
	strcpy_P(host, msg_server_host);

	EthernetClient client;


	if (!client) {
		Serial.println("Ethernet client not available!");
		return;
	}

	Serial.print("HTTP opening connection to ");
	Serial.println(host);
	/*
	if (!ether.dnsLookup(website))
		  Serial.println("DNS failed");
	else
		  Serial.println("DNS resolution done");
	ether.printIp("SRV IP:\t", ether.hisip);
	*/

	if (!client.connect(amsg_server, pgm_read_word(&msg_server_port))) {
		Serial.println("HTTP failed");
		return;
	}

	char d;
	//TODO: add serial number, hash message, JSON
	String postbuf = body;
	String netbuf = "POST ";
	netbuf += path;
	netbuf += " HTTP/1.0\nHost: ";
	netbuf += host;
	netbuf += "\nContent-Type: application/x-www-form-urlencoded\nContent-length:";
	netbuf += postbuf.length();
	netbuf += "\nConnection: close\n\n";
	netbuf += postbuf;
  //compile error on arduino 1.6.2
  //it's just a memory optimization
	//postbuf = NULL;

	Serial.println("HTTP connected");
	Serial.print(netbuf);

	char sockbuf[ netbuf.length() +1];
	netbuf.toCharArray(sockbuf, netbuf.length()+1);
	client.write(sockbuf);
	delay(300);
	while(client.connected()) {
		while(client.available())   {
			d = client.read();
			if (d == '\n')
				Serial.print("\r\n");
			else
				Serial.print(d);
		}
	}
	client.stop();
	Serial.println();
}
开发者ID:markkimsal,项目名称:homesecurity,代码行数:64,代码来源:api_call_http.cpp

示例12: GetWeather

void GetWeather() {
  EthernetClient client;

  static struct hostent *server = NULL;
  if (!server) {
    strcpy(tmp_buffer, WEATHER_SCRIPT_HOST);
    server = gethostbyname(tmp_buffer);
    if (!server) {
      DEBUG_PRINTLN("can't resolve weather server");
      return;    
    }
    DEBUG_PRINT("weather server ip:");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[0]);
    DEBUG_PRINT(":");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[1]);
    DEBUG_PRINT(":");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[2]);
    DEBUG_PRINT(":");
    DEBUG_PRINTLN(((uint8_t*)server->h_addr)[3]);
  }

  if (!client.connect((uint8_t*)server->h_addr, 80)) {
    DEBUG_PRINTLN("failed to connect to weather server");
    client.stop();
    return;
  }

  BufferFiller bf = tmp_buffer;
  char tmp[100];
  read_from_file(wtopts_name, tmp, 100);
  bf.emit_p(PSTR("$D.py?loc=$E&key=$E&fwv=$D&wto=$S"),
                (int) os.options[OPTION_USE_WEATHER].value,
                ADDR_NVM_LOCATION,
                ADDR_NVM_WEATHER_KEY,
                (int)os.options[OPTION_FW_VERSION].value,
                tmp);    

  char *src=tmp_buffer+strlen(tmp_buffer);
  char *dst=tmp_buffer+TMP_BUFFER_SIZE-1;
  
  char c;
  // url encode. convert SPACE to %20
  // copy reversely from the end because we are potentially expanding
  // the string size 
  while(src!=tmp_buffer) {
    c = *src--;
    if(c==' ') {
      *dst-- = '0';
      *dst-- = '2';
      *dst-- = '%';
    } else {
      *dst-- = c;
    }
  };
  *dst = *src;

  char urlBuffer[255];
  strcpy(urlBuffer, "GET /weather");
  strcat(urlBuffer, dst);
  strcat(urlBuffer, " HTTP/1.0\r\nHOST: weather.opensprinkler.com\r\n\r\n");
  
  client.write((uint8_t *)urlBuffer, strlen(urlBuffer));
  
  bzero(ether_buffer, ETHER_BUFFER_SIZE);
  
  time_t timeout = os.now_tz() + 5; // 5 seconds timeout
  while(os.now_tz() < timeout) {
    int len=client.read((uint8_t *)ether_buffer, ETHER_BUFFER_SIZE);
    if (len<=0) {
      if(!client.connected())
        break;
      else 
        continue;
    }
    peel_http_header();
    getweather_callback(0, 0, ETHER_BUFFER_SIZE);
  }
  client.stop();
}
开发者ID:drmcinnes,项目名称:OpenSprinklerGen2,代码行数:79,代码来源:weather.cpp

示例13: mqtt_write

/**
 *
 * @brief MQTT Paho client write interface
 *
 * @param n             pointer to the Network stucture
 * @param buffer        buffer to write out 
 * @param length        number of bytes to write out
 * @timeout timeout_ms  timeout
 *
 * @return Number of by bytes written out 
 *
 * \NOMANUAL
 */
int mqtt_write(Network* n, unsigned char* buffer, int length, int timeout_ms) {
    EthernetClient* client = (EthernetClient*)n->client;
    
    return(client->write((char*)buffer, length));
}
开发者ID:Wind-River,项目名称:rocket-arduino-lite,代码行数:18,代码来源:paho-rocket.cpp

示例14: run


//.........这里部分代码省略.........
    //
    ptr = mb_adu + MB_TCP_DATA;
    *ptr++ = iQty;
    //
    // Write data
    //
    for (i = 0 ; i < iQty/2 ; i++) {
      *ptr++ = highByte(mb_reg[iStart + i]);
      *ptr++ =  lowByte(mb_reg[iStart + i]);
    }
    iTXLen = iQty + 9;
    break;

  case MB_FC_WRITE_REGISTER:
    //
    // 06 (0x06) Write register 
    //
    ptr = mb_adu + MB_TCP_DATA;   
    iStart = word(*ptr++, *ptr++) - 40000;
    //
    // check for valid register addresses     
    //   
    if (iStart < 0 || (iStart - 1) > MB_REGISTERS_MAX) {
      iEC = MB_EC_ILLEGAL_DATA_ADDRESS;
      break;
    }      
    // Unpack and store data
    //
    mb_reg[iStart] = word(*ptr++, *ptr);
    //
    // Build a response 
    //
    iTXLen = 12;             
    break;

  case MB_FC_WRITE_MULTIPLE_REGISTERS: 
    //
    // 16 (0x10) Write Multiple registers
    //
    // modpoll -m tcp -t 4:float -r 40001 -c 1 -1 192.168.x.x 123456.0
    //
    //     [TransID] [ProtID-] [Length-] [Un] [FC] [Start--] [Qty----] [Bc] [float------------] 
    // RX: 0x00 0x01 0x00 0x00 0x00 0x0B 0x01 0x10 0x9C 0x40 0x00 0x02 0x04 0x20 0x00 0x47 0xF1
    //
    // 123456.0 = 0x00 0x20 0xF1 0x47 (IEEE 754)
    //
    // Unpack the start and length
    //
    ptr = mb_adu + MB_TCP_DATA;   
    iStart = word(*ptr++, *ptr++) - 40000;
    iQty = 2*word(*ptr++, *ptr);      
    //
    // check for valid register addresses     
    //   
    if (iStart < 0 || (iStart + iQty/2 - 1) > MB_REGISTERS_MAX) {
      iEC = MB_EC_ILLEGAL_DATA_ADDRESS;
      break;
    }
    //
    // Unpack and store data
    //
    ptr = mb_adu + MB_TCP_DATA+5;
    // todo: check for valid length
    for (i = 0 ; i < iQty/2 ; i++) {
      mb_reg[iStart + i] = word(*ptr++, *ptr++);
    }
    //
    // Build a response 
    //
    iTXLen = 12;
    break;

  default:
    iEC = MB_EC_ILLEGAL_FUNCTION;
    break;    
  }
  //
  // Build exception response if necessary because we were too
  // lazy to do it earlier. Other responses should already be
  // built.
  //
  if (iEC) {
    ptr = mb_adu + MB_TCP_FUNC;
    *ptr = *ptr++ | 0x80;        // flag the function code
    *ptr = iEC;                  // write the exception code
    iTXLen = 9;
  }
  //
  // If there's a response, transmit it
  //
  if (iFC) {
    ptr = mb_adu + MB_TCP_LEN;    // write the header length
    *ptr++ = 0x00;
    *ptr = iTXLen - MB_TCP_UID;  
    clientrequest.write(mb_adu, iTXLen); // send it        
#ifdef MB_DEBUG   
    printMB("TX: ", word(mb_adu[MB_TCP_LEN], mb_adu[MB_TCP_LEN+1]) + MB_TCP_UID);  
#endif                                                
  }
}
开发者ID:Ameba8195,项目名称:Arduino,代码行数:101,代码来源:ModbusTCP.cpp

示例15: loop


//.........这里部分代码省略.........
					// ajax SET info
					else if (getStr.startsWith("/Coordinate/")) {
						digitalWrite(redLed,HIGH);
						GetValue();
						double temp = analogRead(thermRes);
						int phot = analogRead(photoRes);
						client.println("HTTP/1.1 200 OK");
						client.println("Connection: close");
						client.println();
						// JSON
						client.print("{\"coordinate\":{\"X\":");
						client.print(X);
						client.print(",\"Y\":");
						client.print(Y);
						client.print("},\"temp\":");
						client.print(GetTemp(temp),1);
						client.print(",\"light\":");
						client.print(phot);
						client.print(",\"network\":\"");
						client.print(Ethernet.localIP());
						client.print("\",\"file\":[");
						for (int i=0; i<HTTP_FILE; i++) {
							File dFile = SD.open(GET[i]);
							if (dFile) {
								if(i>0) {
									client.print(",");
								}
								client.print("{");
								client.print("\"name\":\"");
								client.print(GET[i]);
								client.print("\",\"size\":");
								client.print(dFile.size());
								client.print("}");
							}
						}
						client.println("]}");
						digitalWrite(redLed,LOW);
					}

					// print other file
					else {
						for(int i=1; i<HTTP_FILE; i++) {
							if (getStr == TYP[0][i]) {
								webFile = SD.open(GET[i]);
								if (webFile) {
									client.println("HTTP/1.1 200 OK");
									client.println(TYP[1][i]);
									if(TYP[2][i] == "1") {
										client.println("Content-Encoding: gzip");
									}
									client.print("Content-Length: ");
									client.println(webFile.size());
									client.println("Cache-Control: max-age=302400, public");
									client.println("Connection: close");
									client.println();
								}
								break;
							}
						}
					}
					// endif check

					// print index.html
					if (indice) {
						webFile = SD.open(GET[0]);
						if (webFile) {
							client.println("HTTP/1.1 200 OK");
							client.println(TYP[1][0]);
							client.print("Content-Length: ");
							client.println(webFile.size());
							client.println("Connection: close");
							client.println();
						}
					}
					// read file and write into web client
					if (webFile) {
						while(webFile.available()) {
							client.write(webFile.read());
						}
						webFile.close();
					}
					
					break;
				}

				if (c == '\n') {
					// last character on line of received text. Starting new line with next character read
					currentLineIsBlank = true;
				} 
				else if (c != '\r') {
					// you've gotten a character on the current line
					currentLineIsBlank = false;
				}
			}
		}
		//delay(1);		// give the web browser time to receive the data
		client.stop();	// close the connection
		digitalWrite(greLed,LOW);
	}
}
开发者ID:hex7c0,项目名称:RadArduino2,代码行数:101,代码来源:sketch.c


注:本文中的EthernetClient::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。