[En-Nut-Discussion] Problem to connect a TCP socket
Julien CHAUSSEC
Julien.Chaussec at ifremer.fr
Mon Jul 18 11:36:37 CEST 2005
Hi every body,
The problem i have is that i can't connect a socket to a server(the
server work). The function NutTcpConnect returned -1 and the number of
the error is 10061.
I don't see where is the problem.
Thank you for your help.
/* programme de test pour la communication ethernet*/
#include <cfg/os.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <dev/nicrtl.h>
#include <dev/debug.h>
#include <sys/version.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pro/dhcp.h>
#ifdef NUTDEBUG
#include <sys/osdebug.h>
#include <net/netdebug.h>
#endif
#include <sys/confnet.h>
#include <sys/confos.h>
//static char buff[1024];
/*
* To save RAM, we store large strings in program space. With AVRGCC we
* would be able to use the PSTR() macro and put the text directly in
* the statement that uses it. But ICCAVR doesn't support anything like
* this. Sigh.
*/
#if defined(__IMAGECRAFT__)
#define CC_STRING "ICCAVR"
#elif defined(__GNUC__)
#define CC_STRING "AVRGCC"
#else
#define CC_STRING "Compiler unknown"
#endif
#define STDOUT_DEVNAME "uart0"
#define STDOUT_DEV devDebug0
#define STDOUT_BAUDRATE 115200
/* adresse mac du contrôleur ethernet */
#define STDNET_MAC { 0x00, 0x0a, 0x59, 0x03, 0x03, 0x0a }
#define STDNET_IPADDR "134.246.147.207"
#define STDNET_IPMASK "255.255.255.0"
void main(void)
{
NutRegisterDevice(&devDebug0, 0, 0)
u_char null_mac[] = STDNET_MAC;
int rc = NutRegisterDevice(&DEV_ETHER, 0x8300, 5);
u_long ip_addr = inet_addr(STDNET_IPADDR);
u_long ip_mask = inet_addr(STDNET_IPMASK);
rc = NutNetIfConfig("eth0", null_mac, ip_addr,ip_mask);
err_net = rc;
if(err_console == 0)
{
if(err_net)
{
puts("ERREUR: pas de reseau\n\r");
}
else
{
printf("configuration du controlleur ethernet OK\n\r");
}
}
int tab1[30];
char tab [50];
int rt;
u_short rport = 5010;
u_short error;
for (;;)
{
TCPSOCKET *sock;
sock = NutTcpCreateSocket();
u_char laddr = *inet_ntoa(ip_addr);
printf(" %u\n\r",laddr);
// this printf doesn't work
if (sock==0)
{
break;
}
NutTcpGetSockOpt ( sock, SO_RCVTIMEO,&tab1,20);
rt = NutTcpConnect( sock,inet_addr("134.246.147.255"), rport);
if(rt ==-1)
{
error = NutTcpError(sock);
printf("%d\n\r", error);
break;
}
sprintf(tab,"bonjour \n\r");
printf("tab=%s\n\r", tab);
printf("socket ok\n\r");
u_char raddr = *inet_ntoa(sock->so_remote_addr);
printf("%u\n\r",raddr);
rt = NutTcpSend(sock, &tab,10 );
printf("rt = %d\n\r", rt);
error = NutTcpError(sock);
printf("%d\n\r", error);
NutSleep(1000);
rt = NutTcpCloseSocket(sock);
printf(" %d\n\r", rt);
}
}
More information about the En-Nut-Discussion
mailing list