I have a MCB2300 board from Keil. I am trying to make my ARM as active socket. since so i was looking into sample program which given to me. From the document
This program is a LEDSwitch Server example. It shows you how to control embedded device from C++ application using TCP/IP connection. This can be either an ethernet, SLIP or PPP link. This example opens an UDP and TCP port for listening and waits for commands coming from PC Client or another eval-board client application. The commands are used to control LED diodes to switch them on and off. In order to run this example, you need to set the network parameters to match your local area network. To test this example, run windows application LEDSwitch and type in the ip address of your Embedded LEDSwitch Server into "Board IP" edit box. Type also the number of transfer port into "Transfer port" edit box. Select one of transfer protocol (TCP or UDP). When the P2 value in windows application is changed, this value is send to eval-board and the LED on board should set as you specified in windows application. The same example can be tested also with another eval-board Client connected to the same LAN.
from this i got some confusion that
The commands are used to control LED diodes to switch them on and off.
what are commends and from where they have to given.
Then
To test this example, run windows application LEDSwitch and type in the ip address of your Embedded LEDSwitch Server into "Board IP" edit box. Type also the number of transfer port into "Transfer port" edit box. Select one of transfer protocol (TCP or UDP)
whats that windows program LEDSwithch? then where i have to type the ip address into "Board IP", and the "Transfer port"?
However From this my ARM board gonna be waiting for client PC's call and may respond after get the call. But i want to make my ARM as active socket. How to do this? Please Help me
I have to guess that you with "active socket" intended the board to be a client.
There are no active or passive sockets even if you can have protocols such as "passive ftp" that makes use of terms such as active or passive.
The client makes the connection. The server accepts the connection.
As you said i made my board as client and 3 PC's as a listener. So i was successful of making them waiting for my data. I was able to display my data on those three PC's Hyperterminal on waiting for a call. But the message i was not able to display as i desired. And i was making port2.0 to port2.4 Pins high and Low as per the connection status. There also i found some problem that making low and high is not what i desired.
Here's my code. Please check it and tell me where i have done the mistakes. Only one line i was getting on all of the terminal continuously. That line is "First Remote Connected".
#include <stdio.h> #include <LPC23xx.H> #include <RTL.h> #include <string.h> #include <Net_Config.h> #define MCLK 48000000 /* Master Clock 48 MHz */ #define TCLK 10 /* Timer Clock rate 10/s */ #define TCNT (MCLK/TCLK/4) /* Timer Counts */ U8 remote_ip1[4][3] = {172, 16, 21, 233, 172, 16, 21, 36, 172, 16, 21, 13 }; U8 tcp_soc; static U8 soc_state; BOOL wait_ack; BOOL tick; void init() { /* Timer 1 as interval timer, reload to 100ms. */ T1TCR = 1; T1MCR = 3; T1MR0 = TCNT - 1; } /*Calling 2nd PC's IP to make a accept the connection*/ void soc_callback(){ U8 data[30]; U8 remote_ip[4]={172, 16, 21, 36}; U8 *sendbuf; switch(tcp_get_state(tcp_soc)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED : FIO2SET=0x08; soc_state=3; tcp_connect(tcp_soc, remote_ip, 1003, 0); if(tcp_check_send(tcp_soc)){ strcpy((char *)data, " Second remote Connected"); //This line want to be displayed whenever made a connection sendbuf = tcp_get_buf (sizeof(data)); memcpy (sendbuf, data, sizeof(data)); tcp_send(tcp_soc, sendbuf, 30 ); return; } break; case TCP_STATE_CONNECT: FIO2CLR=0x08; soc_state=4; if(tcp_check_send(tcp_soc)){ strcpy((char *)data, " Second remote Connected"); sendbuf = tcp_get_buf (sizeof(data)); memcpy (sendbuf, data, sizeof(data)); tcp_send(tcp_soc, sendbuf, 30 ); return; } break; } } /*Calling 3rd PC's IP to make a accept the connection */ void soc_callback1(){ U8 data[30]; U8 remote_ip[4]={172, 16, 21, 13}; //IP of the 3rd PC U8 *sendbuf; switch(tcp_get_state(tcp_soc)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED : FIO2SET=0x10; soc_state=5; tcp_connect(tcp_soc, remote_ip, 1004, 0); //Port number of PC if(tcp_check_send(tcp_soc)){ strcpy((char *)data, " Third remote Connected"); sendbuf = tcp_get_buf (sizeof(data)); memcpy (sendbuf, data, sizeof(data)); tcp_send(tcp_soc, sendbuf, 20 ); return; } break; case TCP_STATE_CONNECT: FIO2CLR=0x10; soc_state=6; if(tcp_check_send(tcp_soc)){ strcpy((char *)data, " Third remote Connected"); sendbuf = tcp_get_buf (sizeof(data)); memcpy (sendbuf, data, sizeof(data)); tcp_send(tcp_soc, sendbuf, 20 ); return; } break; } } void send_data() { U8 data[30]; U8 remote_ip[4] = {172, 16, 21, 233}; // IP of my system U8 *sendbuf; switch(tcp_get_state(tcp_soc)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED : FIO2SET=0x04; soc_state=1; tcp_connect(tcp_soc, remote_ip, 1002, 0); //Port num break; case TCP_STATE_CONNECT: FIO2CLR=0x04; soc_state=2; if(tcp_check_send(tcp_soc)){ strcpy((char *)data, "First Remote Connected");//This is the only line i am getting. sendbuf = tcp_get_buf (sizeof(data)); memcpy (sendbuf, data, sizeof(data)); tcp_send(tcp_soc, sendbuf, 22 ); return; } break; } } /*--------------------------- timer_poll ------------------------------------*/ static void timer_poll () { /* System tick timer running in poll mode */ if (T1IR & 1) { T1IR = 1; /* Timer tick every 100 ms */ timer_tick (); tick = __TRUE; } } U16 tcp_callback(U8 soc, U8 event, U8 *ptr, U16 par) { switch(event) { case TCP_EVT_CONNECT: // soc_state = 2; FIO2SET=0x02; break; case TCP_EVT_ABORT: // soc_state = 0; FIO2CLR=0x01; break; case TCP_EVT_ACK: // wait_ack =__FALSE; FIO2SET=0x01; // FIO2CLR=0x02; break; case TCP_EVT_CLOSE: // Connection Closed FIO2CLR=0x02; break; } return(0); } int main() { PINSEL10 = 0; FIO2DIR = 0x000000ff; soc_state=0; init(); init_TcpNet (); tcp_soc = tcp_get_socket(TCP_TYPE_CLIENT, 0, 30, tcp_callback); // soc_state = 0; while(1) { timer_poll (); main_TcpNet (); // send_data(); /*Checking status of all the connection and sending the messages to the one who's waiting for a call*/ if(soc_state ==2) { soc_callback(); } else if(soc_state ==4) { soc_callback1(); } else { send_data(); } } }