Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 6 months ago. This question has been closed. Reason: Off Topic
receiving strange Data from the server
Hi
I have STM32F429ZI Nucleo board. The board is a client and my PC is a server.
client program (STM32F429)
#include "mbed.h" #include "EthernetInterface.h" DigitalOut l1(LED1); DigitalOut l2(LED2); DigitalOut l3(LED3); DigitalOut l4(LED4); //uLCD_4DGL uLCD (p9,p10,p8); // serial tx, serial rx, reset pin; const int ECHO_SERVER_PORT = 7; const char* ECHO_SERVER_ADDRESS = "192.168.1.20"; // Adress from other Mbed int main () { EthernetInterface eth; const char* ip = "192.168.1.22"; // MBED A = 1; MBED B = 2 const char* mask = "255.255.255.0"; const char* gateway = "192.168.1.1"; eth.init(ip, mask, gateway); //I'dont use DHCP bacuse i use two mbeds eth.connect(); printf("Client IP Address is %s\n", eth.getIPAddress()); // Connect to Server TCPSocketConnection socket; while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) > 0) { printf("Unable to connect to (%s) \non port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); wait(1); } printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS); // Send message to server char hello[] = "Hello World"; printf("Sending message to Server : '%s' \n",hello); socket.send_all(hello, sizeof(hello) - 1); // Receive message from server char buf[256]; int n = socket.receive(buf, 256); buf[n] = '\0'; printf("Received message from server: '%s'\n", buf); // Clean up socket.close(); eth.disconnect(); while(true) {} }
Server Program (PC)
import socket import signal import sys def signal_handler(signal, frame): print 'You pressed Ctrl+C!' s.close() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) print 'Server Running at ', socket.gethostbyname(socket.gethostname()) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 7)) s.listen(1) while True: conn, addr = s.accept() print 'Connected by', addr while True: char data = conn.recv(256) if not data: break conn.sendall(data) conn.close()
The connection is established between the client and the server. The client is sending hello word but the server is showing strange output.
Could you please help me on the mentioned issue.
Thank you
Nada