TCP Client

New to XMOS and XCore? Get started here.
etori90
Newbie
Posts: 1
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;
}
}
}
User avatar
CousinItt
XCore Addict
Posts: 167
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: 389
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.
nick
Member
Posts: 9
Joined: Tue Jan 07, 2020 10:35 am

Postby nick » Fri Mar 27, 2020 2:16 pm

I think that just before doing the i_xtcp.connect() you have to create a socket:

conn = i_xtcp.socket(XTCP_PROTOCOL_TCP);

Who is online

Users browsing this forum: vicacid and 1 guest