Home > other >  The TCP client and STM32F107 used, connect to PC TCP server program problem
The TCP client and STM32F107 used, connect to PC TCP server program problem

Time:11-06

The client and server connection cannot be normal connection, occasionally can even,
Trouble everybody look, program where there is a problem,
PC TCP server program, written in VB using WinSock control
Private Sub Form_Load ()
'the LocalPort attribute is set to an integer,
'and then call Listen method,

TcpServer. Protocol=sckTCPProtocol
TcpServer. LocalPort=4000
TcpServer. Listen
End Sub

Private Sub tcpServer_ConnectionRequest (ByVal requestID As Long)
'check if control of the State property is closed,
'if not,
'before you accept a new connection to close the connection,
If TcpServer. State & lt;> SckClosed Then TcpServer. Close
With the requestID parameters' accept
'connection,

TcpServer. Accept requestID
End Sub

Private Sub tcpServer_DataArrival (ByVal bytesTotal As Long)
'for entering data declare a variable,
'call GetData method, and gives the data to called txtOutput
'the TextBox Text property,

Dim strData As String
TcpServer. GetData strData
TxtOutput. Text=strData
End Sub


Under a machine using STM32F107, TCP client program
Int main (void)
{
.
LwIP_Init ();
//UDP_rx_Init ();
TCP_Client_init ();
.
While (1) {
.
}

}

Void TCP_Client_init (void)
{
Struct tcp_pcb * PCB;
Struct ip_addr ipaddr;
//int localPort;
//localPort=1000 + ip_address_last (int);
IP4_ADDR (& amp; Ipaddr, 192168,0,2);//server IP192.168.0.2
PCB=tcp_new ();
Tcp_bind (PCB, IP_ADDR_ANY, 1001);
Tcp_connect (PCB, & amp; Ipaddr, 4000, tcp_client_connected);
}

Err_t tcp_client_connected (void * arg, struct tcp_pcb * PCB, err_t err)
{
//TcpPCB=PCB;
Tcp_write (PCB, the GREETING, strlen (GREETING), 0).//output Str
Tcp_recv (PCB, tcp_Receive);
Return ERR_OK;
}

The static err_t tcp_Receive (void * arg, struct tcp_pcb * PCB, struct pbufs * p_1, err_t err)
{
Unsigned char * temp.
Unsigned int I;

If (p_1!=NULL)/* if the data received is empty */
{rec_data_size=(* p_1). Tot_len;
Temp=p_1 - & gt; Content;
for(i=0; i{
Eth_rec_data [I]=* temp;
Temp++;
}
Pbuf_free (p_1);/* */release the buffer data
Rec_ethernet_flag=1;
}
Return ERR_OK;
}
  • Related