Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

NicheStack Wont Connect to Server

Hello everyone,

I'm trying to set up some TCP communications between a PC and this DE2-115 board.

When I fire up the system I get this:

--- Quote Start ---

InterNiche Portable TCP/IP, v3.1

Copyright 1996-2008 by InterNiche Technologies. All rights reserved.

prep_tse_mac 0

MAC Address is: 0:7:ED:FF:CD:F

DHCP Enabled.

prepped 1 interface, initializing...

[tse_mac_init]

INFO : TSE MAC 0 found at address 0x06002000

INFO : PHY Marvell 88E1111 found at PHY address 0x10 of MAC Group[0]

INFO : PHY[0.0] - Automatically mapped to tse_mac_device[0]

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link...

INFO : PHY[0.0] - Auto-Negotiation PASSED

INFO : PHY[0.0] - Checking link...

INFO : PHY[0.0] - Link established

INFO : PHY[0.0] - Speed = 100, Duplex = Full

OK, x=0, CMD_CONFIG=0x00000000

MAC post-initialization: CMD_CONFIG=0x04000203

[tse_sgdma_read_init] RX descriptor chain desc (1 depth) created

mctest init called

IP address of et1 : 204.177.5.2

Created "Inet main" task (Prio: 2)

Created "clock tick" task (Prio: 3)

Acquired IP address via DHCP client for interface: et1

IP address : 192.168.2.193

Subnet Mask: 255.255.255.0

Gateway : 192.168.2.1

Attempting to Connect to Target Server at 192.168.2.129 on Port: 502

Returned 8500446 as socket.

Error Connecting To Server.

Error: Connect Subroutine Has Failed.

--- Quote End ---

The function that does the networking bits is here...I have a server listening on that IP address at that specific port...

--- Quote Start ---

int sd,i;

struct sockaddr_in server;

//Zero out structure

bzero(&server, sizeof(server));

//Obtain Socket For Connection

if((sd=socket(AF_INET,SOCK_STREAM,0))<0){

printf("Error Obtaining Socket");

printf("Error: ", strerror(errno));

return -1;

}

else{

printf("Returned %d as socket.\n",sd);

//Set Connection Details

server.sin_family=AF_INET;

server.sin_port = htons(port);

inet_pton(AF_INET,"192.168.2.129", server.sin_addr.s_addr);

//Connects

if(connect(sd,server.sin_addr.s_addr,sizeof(server))<0){

printf("Error Connecting To Server.\n");

printf("Error: %s", strerror(errno));

return -1;

}

else{

return sd;

}

//Shouldn't have gotten down here, so error out anyway.

return -1;

--- Quote End ---

Does anyone have any pointers/tips/comments...

I'd appreciate it very much..

Thanks

-Kris

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I would start with the obvious stuff first, make sure the path from that point to your destination at port 502 works and there are not any firewalls blocking you.

    I use a utility "netcat" that is common on Linux boxes. Plug into the same router, fire up netcat and try to connect to that machine on port 502 using netcat. If you don't know how to use netcat, check the man page or google. If you can get to that machine through netcat, you know the problem is with your dev board.

    David
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Well, the problem is most definitely on the dev board as I suspected originally.

    I fired up Netcat and was able to connect to the server no problem.

    Anyone see anything wrong with my code? Its pretty standard stuff..

    The dev board is ping-able and retrieves IP address via DHCP...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Well, after some debugging. I put some error checking on the inet_pton function and discovered it wasnt actually working. So the struct was never getting populated with address info which caused the connect function to..well not connect.

    However now I am getting a "no free buffer" error:

    --- Quote Start ---

    Attempting to Connect to Target Server at 192.168.002.196 on Port: 502

    Returned 8500502 as socket.

    Address was successfully converted.

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    No free buffers for rx

    Error Connecting To Server.

    Error: Connect Subroutine Has Failed.

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Never mind those Rx buffer errors. I changed afew things and they are no longer coming up...

    Connect tries to connect, hangs there, then returns -1, but it never sets errno.

    I tried manually setting errno, and it reads out perfectly fine.

    Any ideas why connect wont set errno?

    --- Quote Start ---

    if(connect(sd, (struct sockaddr*)&server,sizeof(server))<0){

    printf("Error Connecting To Server.\n");

    fprintf(stderr,"Error: %d %s \n",errno, strerror(errno));

    return -1;

    }

    else return sd;

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi James,

    I'm trying to do the same you are on a DE2-115, getting a connection between it and a PC.

    How has your project gone?