Hi,
I'm currently working with MQX 3.8.1, Codewarrior 10.2, and the Kinetis K60 tower module, and I'm having trouble connecting using my tower as a client to my laptop. I was wondering if anyone could tell me what I'm doing wrong.
Setup:
- Set laptop ethernet port to IP: 192.168.3.101 and gateway: 192.168.3.1
- trying to open a socket on the K60 to act as a client to my laptop (acting as a server)
- attempting to reach any website to prove that it works, google.com or any website
What does work so far:
- Ethernet connection is successful and RTCS is up and running (started a new MQX project and added RTCS/shell support which ran successfully)
- I set up an error checking for binding the socket and it didn't hit the error so I'm assuming that binding works.
Problems:
- Hit error message for connecting the socket so it isn't connecting the socket.
Questions:
- Is the destination IP address supposed to be the IP for google or the server. (I tried using 192.168.1.101 which is the IP of my server but that failed)
- what is being assigned to these declarations (i've noticed these keep popping up in numerous examples)
- _ip_address ipaddr;
- socketaddr_in addr;
- Are there any other examples besides the Twitter example and the socket training video/pdf? These seem to have more examples for the server side but I'm trying to set up the K60 as a client to a database later on.
Code:
| #define HOST | | "google.com" |
| #define DESTIP | | IPADDR(192,168,3,1) |
#define ENET_DEVICE 0
#define RTCS_DHCP 0
#define ENET_IPADDR IPADDR(192,168,3,101)
#define ENET_IPMASK IPADDR(255,255,255,0)
#define ENET_GATEWAY IPADDR(192,168,3,1)
#define RTCS_PPP 0
void connect_task(uint_32 initial_data)
{
_ip_address ipaddr;
uint_32 sock;
uint_32 result;
sockaddr_in addr;
char* test = "This is a test for data stream";
while(1)
{
if (_mutex_lock(&print_mutex) != MQX_OK)
{
printf("Mutex lock failed.\n");
_task_block();
}
rtcs_init();
addr.sin_family = AF_INET;
addr.sin_port = 80;
addr.sin_addr.s_addr = DESTIP;
sock = socket(AF_INET, SOCK_STREAM, 0);
result = bind(sock, &addr, sizeof(addr));
if(result != RTCS_OK)
{
printf("ERROR the socket could not be bound");
return;
}
addr.sin_port = 80;
addr.sin_addr.s_addr = ipaddr;
result = connect(sock, &addr, sizeof(addr));
if(result != RTCS_OK)
{
printf("ERROR the socket could not CONNECT");
}
else
{
printf("Connected to %lx, port %d",addr.sin_addr.s_addr, addr.sin_port);
}
printf("\nREADY TO SEND DATA!!!!!!!!!!!!!!!!!");
_mutex_unlock(&print_mutex);
_task_block();
}
}
Thanks,
Khoa Nguyen