TCP Client Topic is solved

New to XMOS and XCore? Get started here.
etori90
Member++
Posts: 26
Joined: Thu Sep 05, 2019 6:49 am

TCP Client

Postby etori90 » Wed Mar 25, 2020 12:46 pm

Hi there.

I am a student studying network.
I am trying to make an example TCP Server, client code using exploer kit,
Like the Winsock example code (server, client) on google.
I want to communicate between PC (i used Winsock, it is a server) and exploer kit (it is a Client).
I have only seen the XMOS code that works as a Server.

1. Does anyone have an example code that the explorer kit works as a client?


=========================================================================================================

I have a client code as below. And I expected the three handshakes to work in the i_xtcp.connect() part

However, it is only compiled and does not work.

When I use the connect() function, I expected

Three handshakes ==> XTCP_NEW_CONNECTION ==> i_xtcp.send() ==> XTCP_CLOSED

2. Is it correct??

If I'm wrong, Could you tell me how to use 'void connect()' (in xtcp.h (it is lib_xtcp V 6.0)) ?

Please, Someone help me :(



void connect_t(client xtcp_if i_xtcp, int remote_port)
{
//remotre_port is 6633
xtcp_connection_t conn;
unsigned return_len = 0;

char rx_buffer[RX_BUFFER_SIZE] = {0};
char tx_buffer[RX_BUFFER_SIZE] = {'H', 'E', 'L', 'L', 'O'}; // I want to send it to PC(Server, i used Winsock)

unsigned char ipaddr[4] = {192, 168, 1, 21}; // PC addr

while (1) {
select {
case i_xtcp.packet_ready():
i_xtcp.get_packet(conn, (char *)rx_buffer, RX_BUFFER_SIZE, return_len);
switch(conn.event) {
case XTCP_IFUP: // link up!

i_xtcp.connect (remote_port, ipaddr, XTCP_PROTOCOL_TCP); // try to Connect PC (Server)
break;
case XTCP_RECV_DATA:
if(rx_buffer[0] == 'a') {
i_xtcp.abort(conn);
}
for(int i=0; i<return_len; i++) {
if(tx_buffer != rx_buffer) {
printf("Error: Mismatch");
}
}
i_xtcp.send(conn, tx_buffer, 5);
break;

case XTCP_NEW_CONNECTION:
i_xtcp.send(conn, tx_buffer, 5); //Connection, send Hello msg !
break;

case XTCP_ABORTED:
exit(0);
break;

case XTCP_CLOSED:
break;
}
break;
}
}
}
View Solution
User avatar
CousinItt
XCore Addict
Posts: 179
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Wed Mar 25, 2020 8:00 pm

Start with a known good example, like the UDP server or web server examples that XMOS provides. Set up your PC with Waveshark and a packet generator such as Packet Sender, and use them with the example. That way you can confirm that your build process, your hardware and your network are all working correctly.

Once you've done that, you can modify the code to try the TCP client and test its operation methodically.
User avatar
akp
Respected Member
Posts: 448
Joined: Thu Nov 26, 2015 11:47 pm

Postby akp » Fri Mar 27, 2020 1:55 pm

I started with the webserver demo. It's not very robust but it will get you going.
etori90
Member++
Posts: 26
Joined: Thu Sep 05, 2019 6:49 am

Postby etori90 » Mon Mar 30, 2020 8:48 am

First of all, thank you very much for your answers.
As your advice, I started with the webserver demo code.

I have referenced these.
1. https://github.com/xmos/lib_xtcp/tree/m ... server/src

2. viewtopic.php?t=6942
I modifed 'src/xtcp_lwip/core/' to 'src/xtcp_lwip/core' in 'module_build_info file'. (lib_xtcp v6.0.0)
(I was very embarrassed at first because an error occurred in the library provided by xTIMEcomposer. :-( )

In the main, I added and modified the following code.

- #define XTCP_STACK_LWIP 1

- static unsigned char mac_address[6] = {0x1,0x2,0x3,0x4,0x5,0x6};

- on tile[0]: xtcp_lwip(i_xtcp, NUM_XTCP_CLIENTS, null,
i_cfg[CFG_TO_XTCP], i_rx[ETH_TO_XTCP], i_tx[ETH_TO_XTCP],
null, ETHERNET_SMI_PHY_ADDRESS,
mac_address, null, ipconfig); // I changed null to mac address

- xtcp_ipconfig_t ipconfig = {
{ 192, 168, 1, 9 }, // ip address
{ 255, 255, 255, 0 }, // netmask
{ 192, 168, 1, 1 } // gateway
};

- I added random.h file

It works well as a server.

========================================================================================================================

While writing, I found the cause of why it didn't work.
It is 'lib_xtcp' problem. It works 'lib_xtcp' supported by GitHub, not xTIMEcomposer.
In my opinion, 'lib_xtcp' supported by xTIMEcomposer was not updated. (Because '/' of module_build_info file was not removed. My wasted time... : -( )

Anyway, Thank you all for your answers.
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: No registered users and 2 guests