[En-Nut-Discussion] Problem to connect a TCP socket

Yoo, Young-Dong uc at techiz.com
Mon Jul 18 13:22:54 CEST 2005


Hi!, Julien

I think you should change server ip.
Currently, Your server ip is 134.246.147.255.
So, if you send your data to that server IP, maybe generate broadcast
packets.
Error number 10061 is "ECONNREFUSED" (connectiong refujed).
I show you source programs.
As follows:

<net/ipout.c>
int NutIpOutput(u_char proto, u_long dest, NETBUF * nb)
{
...
if (nif->if_type == IFT_ETHER) {
        /* 
         * Detect directed broadcasts for the local network. In this
         * case don't send ARP queries, but send directly to MAC broadcast
         * address. 
         */
        if ((gate == 0) && ((dest | nif->if_mask) == 0xffffffff)) {
            memset(ha, 0xff, sizeof(ha)); <== maybe your case. {broadcase
address}
        } else if (NutArpCacheQuery(dev, gate ? gate : dest, ha)) {
            NutNetBufFree(nb);
            return -1;
        }
        return (*nif->if_output) (dev, ETHERTYPE_IP, ha, nb);
...
}
<net/tcpsm.c>
static void NutTcpStateSynReceived(TCPSOCKET * sock, u_char flags, TCPHDR *
th, NETBUF * nb)
{
...
if (flags & TH_RST) {
        if (sock->so_pc_tq)
            NutTcpStateChange(sock, TCPS_LISTEN);
        else 
            NutTcpAbortSocket(sock, ECONNREFUSED); <==== this case. (maybe)
        NutNetBufFree(nb);
    	sock->so_retran_time = 0;
        NutTcpDiscardBuffers(sock);
        return;
    }
...
}



-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Julien CHAUSSEC
Sent: Monday, July 18, 2005 6:37 PM
To: Ethernut User Chat (English)
Subject: [En-Nut-Discussion] Problem to connect a TCP socket

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);	
     }
}

_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list