conectar mbed a través de tcp/ip a portatil

I wish connect mbed to my laptop. In the Laptop are running a python program that open a local port . But I can't make a conection sucessfully.

laptop program server written in python

  1 import socket 
  2 s = socket.socket()
  3 s.bind(("localhost", 9999))
  4 s.listen(1)
  5 sc, addr = s.accept()
  6 print "Recibo conexion de " + str(addr[0]) + ":" + str(addr[1])
  7 
  8 while True:
  9   recibido = sc.recv(1024)
 10   if recibido == "by":
 11     break
 12   print "Recibido:", recibido
 13 
 14   sc.send(recibido)
 15 
 16 print "adios"
 17 sc.close()
 18 s.close()

mbed program

<<#include "mbed.h"
#include "EthernetNetIf.h"
#include "TCPSocket.h"

EthernetNetIf eth(
  IpAddr(192,168,1,2), //IP Address
  IpAddr(255,255,255,0), //Network Mask
  IpAddr(192,168,1,1), //Gateway
  IpAddr(192,168,1,1)  //DNS
);

TCPSocket tcp;
Serial pc(USBTX,USBRX);

void onTCPSocketEvent(TCPSocketEvent e)
{
    switch(e)
    {
        case TCPSOCKET_CONNECTED:
            pc.printf("Connected\n");
        break;
        
        case TCPSOCKET_ACCEPT:
           pc.printf("Accepted\n");
        break;
        
        case TCPSOCKET_READABLE:
           pc.printf("Readable\n");
        break;
        
        case TCPSOCKET_WRITEABLE:
           pc.printf("Writeable\n");
            pc.printf("Escribiendo \n\r");
        break;
        
        case TCPSOCKET_CONTIMEOUT:
            pc.printf("Timeout\n");
        break;
        
        case TCPSOCKET_CONRST:
            pc.printf("Reset\n");
        break;
        case TCPSOCKET_CONABRT:
            pc.printf("Aborted %d\n",TCPSOCKET_CONABRT);
        break;
        
        case TCPSOCKET_ERROR:
            pc.printf("Error\n");
        break;
        
        case TCPSOCKET_DISCONNECTED:
            pc.printf("Disconnected\n");
            tcp.close();
        break;    
    }
}

int main() 
{
    pc.printf("Welcome to wireFUSE\n\r");
    pc.printf("Setting up...\n\r");
    EthernetErr ethErr = eth.setup();
    if(ethErr)
    {
        pc.printf("Error %d in setup.\n\r", ethErr);
        return -1;
    }
    pc.printf("Setup OK\n\r");
  
  
    Host server(IpAddr(192,168,1,35),5000);
   //laptop ip and port
  
  // display IP address and port# of server
  IpAddr serverIp = server.getIp();
  int port = server.getPort();   

  pc.printf("Connecting... %d.%d.%d.%d:%d\r\n", serverIp[0],serverIp[1],serverIp[2],serverIp[3],port);
  TCPSocketErr bindErr = tcp.connect(server);
  pc.printf("Connected\n");
  tcp.setOnEvent(&onTCPSocketEvent);


//Poll the networking stack     
    while (true)
    {    
      Net::poll();
         
    }

}

Any ideas how to solve the problem?

30 Aug 2011

if you insert your code between the 'code' tags <<code>> and <</code>> it will be much more readable :-)

Click on "Editing tips" while you are entering your message.

Like this:

int main(){
    printf("Hello World");
} 

Gert van der Knokke wrote:

if you insert your code between the 'code' tags <<code>> and <</code>> it will be much more readable :-)

Click on "Editing tips" while you are entering your message.

Like this:

int main(){
    printf("Hello World");
} 

thanks is my first post and I'm not familiar with wiki syntax still.

a greeting

Roberto Sainz Aja Sainz Maza rsainzaja wrote:

Host server(IpAddr(192,168,1,35),5000); laptop ip and port

the port is 9999 instead of 5000 was an copy/paste error.

the output is:

Quote:

Connecting... 192.168.1.35:9999 Connected Aborted 6

return"Aborted 6" why?

Hi guys, I answer to my problem myself. My laptop's firewall was on and was blocking all my connections. For this reason, could not establish a connection. Thank you all.