TCP burst to hostname

Discussion to talk about software related topics only.
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

TCP burst to hostname

Post by MrSteel »

Hi,

I need help with SBL2e TCP communication. For a first time I used TCP client example to send some test string to server. Everything is working good but I need to send TCP burst to hostname not directly to IP address. Is this possible ?

Can you send TCP data to some hostname.com:1000 ? Is any way to programme this to SBL2e ?

Thank you for the support.

Best regards,
Blaž
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: TCP burst to hostname

Post by pbreed »

You need to use DNS to convert name to ip address....
All IP traffic is converted from name to ip address before its sent....

#include <dns.h>
/*
GetHostByName
Returns:
#define DNS_OK (0)
#define DNS_TIMEOUT (1)
#define NDS_NOSUCH_NAME (2)
*/
/* Pass 0 in for dns_server and it uses the stored value */
int GetHostByName( const char *name, IPADDR *pIpaddr, IPADDR dns_server, WORD timeout, WORD TYPE = DNS_A );

so suppose you have

const char * hostName="www.somehost.com";


IPADDR Address_of_host;

if(GethostByName(hostName,&Address_of_host,0,5*TICKS_PER_SECOND)==DNS_OK)
{//Successfully resolved name... now to use it
//Address_of_host holds the ip address.
}
else
{//Failed to resolve name....
}
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

Re: TCP burst to hostname

Post by MrSteel »

My code:

Code: Select all

const char * AppName = "Test";
const char * hostName= "test.domain.com";

void UserMain(void *pd)
{
    SimpleUart(0,SystemBaud); 			// Initialize debug UART
    assign_stdio(0);          		// Use UART 0 for STDIO

    InitializeStack();           // Initialize TCP stack
    EnableAutoUpdate();          // Enable network downloads to target
    OSChangePrio( MAIN_PRIO );   // set standard UserMain task priority

    iprintf( "Starting test program\r\n" );
    IPADDR Address_of_host = AsciiToIp("91.223.182.54");
    
    while ( 1 )
    {
		OSTimeDly( 1 );

		if( GetHostByName(hostName,&Address_of_host,0,5*TICKS_PER_SECOND) == DNS_OK)
		{
			iprintf( "Address_of_host holds the ip address.\r\n" );
		}
		else
			 iprintf( "Failed to resolve name...\r\n" );

    }
}

I always get Faild to resolve name ? Did I make any mistake ? What could be wrong ? And why do I have MyIpDNS varible null ?

Best regards,
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: TCP burst to hostname

Post by pbreed »

Are you using DHCP or a static address?

If its a static address did you give it a DNS server and gateway address?
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

Re: TCP burst to hostname

Post by MrSteel »

Hi,

I am using static and now I got DNS figure it out. Now is working. Thank you for the help.

But still I got one question more. I want to send data to server trough TCP communication. But there is one trick. The server is listening for data but not answering. So if I use TCP Client example I got errors!

I cant use tcp.Connect(DestIP, DestPort, 40) because I always get false connection! I want to do this:

tcp.Connect(DestIP, DestPort, 40)
tcp.Printf("This message is from the TCP Server\r\n" );
tcp -> Output answer from server!
tcp.Close();

Can I use some code from examples or how to do this ?
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

Re: TCP burst to hostname

Post by MrSteel »

Hi,

Any solution on my question ?

Best regards,
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: TCP burst to hostname

Post by rnixon »

Hello,

I think its a language thing, but your question does not make sense to me and you have not provided nearly enough information for anyone to help you.

What is a "false" connection? Does it seem to be connected but is not, or are you getting an error that the connection failed? What is the error code if it fails?

What type of server are you connecting to? Can you connect to it using telnet and the appropriate port number?

When you do a wireshark trace what do you see?
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

Re: TCP burst to hostname

Post by MrSteel »

Hi,

Now the communication is working. There was bug on server!

Thank you for the help.
MrSteel
Posts: 8
Joined: Thu Jun 27, 2013 11:00 am

Re: TCP burst to hostname

Post by MrSteel »

Hi,

I got problems with DNS again! I cant get IP addres from hostname!

My network configuration:

IP: 192.168.1.254
255.255.255.0
192.168.1.1.
192.168.1.10 // DNS server

code:

Code: Select all


        #include <dns.h>

        const char * hostName="www.google.com";
	IPADDR Address_of_host = 0;

	if(GetHostByName(hostName,&Address_of_host,0,5*TICKS_PER_SECOND) == DNS_OK)
	{
		iprintf("IP address: %I\r\n", hostName );
	}
	else
	{
		iprintf("DNS error!\r\n" );
	}
I always get error 3! or in this case "DNS error!"

Thank you for the help.
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: TCP burst to hostname

Post by dciliske »

Then the problem is your DNS server... Given that it is a from an address block reserved for DHCP, I'm assuming that you control the DNS server. Either that, or you are pointing to the wrong address. What happens if you try to set your PC's DNS server to that address? Can you still browse the internet?

If the address is correct and you can successfully talk with the DNS server, then the issue lies in your configuration of the DNS server. The problem is probably one of two things: a) you have setup the DNS server as a Fully resolving, caching nameserver or b) if you've setup the DNS server as DNS forwarder, you don't have a forwarding address set.

If you find that DNS requests are majorly delayed, but eventually return, then you likely have the first problem. Change the server to be a DNS forwarder, and it should resolve the issue. If you find that DNS requests are failing as unresolvable, then you probably have the second issue. In this case, you need to explicitly set the address of the server(s) to forward DNS requests to.

-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
Post Reply