This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Can't connect properly (TCP/IP)
- From: Andrew Lunn <andrew at lunn dot ch>
- To: "EXTERNAL Gladis Olaf (Praktikant; CR/AEM)" <external dot Olaf dot Gladis at de dot bosch dot com>
- Cc: ecos-discuss at ecos dot sourceware dot org
- Date: Wed, 31 Oct 2007 17:02:51 +0100
- Subject: Re: [ECOS] Can't connect properly (TCP/IP)
- References: <F6E0DC7B316B5342918DD39721EE25B101615960@si-mail07.de.bosch.com>
> Here it is:
> #include <network.h>
> ...
> int Tcp_connectToServer()
> {
> int sock;
> int n;
> struct sockaddr_in serv_addr;
>
> sock = socket(AF_INET, SOCK_STREAM, 0);
> if (sock < 0)
> {
> //Error while open socket
> return -1; //TODO return types
> }
>
> memset(&serv_addr,0,sizeof(serv_addr));
> serv_addr.sin_family = AF_INET;
> serv_addr.sin_addr.s_addr = htonl(0xC0A85001);
> //192.168.80.1
> serv_addr.sin_port = htons(TCP_MAIN_PORT); //5000
> serv_addr.sin_len = sizeof(serv_addr);
>
> n=connect(sock,(struct sockaddr
> *)&serv_addr,sizeof(serv_addr));
> if (n < 0)
> {
> //Connecting Error
> return -1;
> }
> n=0;
>
> n = write(sock,"testcase",strlen("testcase"));
> if (n < 0)
> {
> //writing error
> return -1;
> }
>
> return 0;
> }
I would add some diag_printf() so you know what has been executed and
if there are any errors returned.
I would also use tcpdump/ethereal etc, to watch the packets flowing
backwards and forwards. You should be able to see this data in a
packet etc.
Andrew
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss