11 years, 7 months ago.

TCP Socket Client for Java

Hey everybody!

I've written a java application which corresponds with the mbed. I created a HttpServer on the Mbed and used RPC Variables to set variables on the mbed. What I now want to do is a TCP Socket connection, in which the mbed will be the client and the pc with the java application the Server. I already succesfull created client/server in java and was able to connect and send/receive data.

But I'm lost in writting a TCP Client on the mbed. I used the Example from Roy van Dam: http://mbed.org/users/NegativeBlack/code/NetworkAPI/wiki/tcp-client-example . which didn't work. Now I am trying a very basic client programm to connect to the socket which i took from Socket handbook and it looks like this:

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

static const char*          mbedIp       = "192.168.1.128";  //IP
static const char*          mbedMask     = "255.255.255.0";  // Mask
static const char*          mbedGateway  = "192.168.1.1";    //Gateway
static const char*          pcIp         = "192.168.1.65";
static int port = 1234;

main()
{
    printf("init\n");
    EthernetInterface interface;
    interface.init(mbedIp, mbedMask, mbedGateway);
    printf("connecting....\n");
    interface.connect();
    printf("IP Address is %s\n\r", interface.getIPAddress());
    
    
    TCPSocketConnection connection;
    while(connection.connect(pcIp, port) <0){
        printf("Unable to connect to socket!");
        wait(1);
    }
}

But its also not possible to connect to the java Server....

Am I missing something? Or does someone have a very simple/basic implementation of a java server / mbed socket client?

Thanks in advance & Best Regards Michael

Question relating to:

Be the first to answer this question.