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:
What does work so far:
Problems:
Questions:
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
解決済! 解決策の投稿を見る。
Perhaps you have a firewall preventing the port to be available for connections. Try to disable the firewall of internet security programs.
I have created and example that I have tested with Socketest. I am attaching here. It is pretty simple. It sends data from the socket to the serial and from the serial to the socket.
Hope this helps.
Regards,
-Garabo
Hi Khoa,
Perhaps this appnote can help you http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4417.pdf
The source code is provided here:
http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4417SW.zip
this code is doing the same you are trying. Crop the code that does the socket negotiation and let me know if worked.
Good luck,
Best Regards,
Garabo
Hi,
I've already referred to this AN for reference and I'm able to establish a TCP connection to a designated endpoint but the send function for sockets is blocking because the connection hasn't been accepted. Is there a program I can use to test this? I've using a program called SocketTest v3.0.0 which created a server TCP socket on my windows laptop to listen for incoming connections but it didn't seem to work.
Also, since the send function is blocked, due to not having a server accept the connection, will the function automatically go back into ready whenever the connection is accepeted?
Thanks,
Khoa Nguyen
Hi Khoa,
I have the same issue that you had with the TCP/IP socket. The connection is not accepted,, then blocks the task.
How did you fix the problem?
Thanks.
Oscar
Perhaps you have a firewall preventing the port to be available for connections. Try to disable the firewall of internet security programs.
I have created and example that I have tested with Socketest. I am attaching here. It is pretty simple. It sends data from the socket to the serial and from the serial to the socket.
Hope this helps.
Regards,
-Garabo