TCP Client
Posted: 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;
}
}
}
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;
}
}
}