10 years, 3 months ago.

A question about socket TCP client

#include "mbed.h"
#include "string.h"
#include "EthernetInterface.h"

Serial pc(USBTX,USBRX);
int ret;
DigitalOut myled(LED1);

int main() {
    EthernetInterface eth;
    eth.init("192.168.3.10","255.255.255.0","192.168.3.1"); //Use DHCP
    eth.connect();
    pc.printf("IP Address is %s\n", eth.getIPAddress());
    
    
    TCPSocketConnection sock;
    ret = sock.connect("192.168.3.1", 5188);
    if (ret < 0)
       pc.printf("Socket is not connected\n");
    else 
       pc.printf("Socket is connected\n");
       
    char http_cmd[] = "GET /media/uploads/mbed_official/hello.\nGET /media/uploads/mbed_official/hello.\n";
 

    while(1)
    {
             ret = sock.send_all(http_cmd,sizeof(http_cmd)-1);
             if (ret < 0)
             {
                 pc.printf("Failed to send\n");
                 break;
                 }
             myled = !myled;
             wait(1);
             
    }
      
    sock.close();
    
    eth.disconnect();
}

This is my code for lpc1768, the question is if i choose

char http_cmd[] = "GET /media/uploads/mbed_official/hello.\n";

the string length is 40 , it runs ok even I set wait_us(500). However, it is not stable whatever I set for the waiting time

if the string length is 80, it can not work, the serial port shows that IP Address is 192.168.3.10 Socket is connected Failed to send

if my tcpserver is working for win7, the waiting time should be set larger than 0.4s, or it will not work

SOCKET sockConn=accept(sockSrv,(SOCKADDR*)&addrClient,&len);
char recvBuf[1024];
	
while(1)
{
	recv(sockConn,recvBuf,1024,0);
		printf("%s\n",recvBuf);
		memset(recvBuf,0,sizeof(recvBuf));
	}
	closesocket(sockConn);
}

if my tcpserver is working for ubuntu, the waiting time can be set as 500us, I want to know why, I need to transmit very large data from sensor to PC, about 48kb/s

Be the first to answer this question.