Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-15-2014, 11:59 PM   #1
parvathi reddy
LQ Newbie
Registered: Mar 2014
Posts: 11

Rep: Reputation: Disabled
Tcp/ip socket server and client program - Redhat linux server 5(eclipse CDT)

tcp ip socket- server program

This is my sample socket tcp ip program , problem here is when i give working ip address and port number, it is showing default ip address as and it is Waiting on (1978=port number) i.e., "connection on %d...", SERVER_PORT.

void socket_server_demo(void){
int iserver_socket = -1;
int iclient_socket = -1;
unsigned char bTemp[1024];
unsigned int iTemp = 0;
int i;
int active_net = 0;
char client_addr[255];
unsigned int client_port = 0;
char iflist[16][IFNAMSIZ];
struct ifreq ifr;
int error;
printf(ALG_CENTER, "socket server");
iTemp = netif_get_list(iflist, sizeof(iflist)/IFNAMSIZ);
for (i = 0; i < iTemp; i++){
memset(&ifr, 0, sizeof(ifr));
netif_get_flags(iflist[i], &ifr);
if (ifr.ifr_flags & IFF_RUNNING){
netif_get_ipaddr(iflist[i], &ifr);
printf(ALG_CENTER, "Address:%s:%d", inet_ntoa(((structsockaddr_in*)&ifr.ifr_addr)->sin_addr), SERVER_PORT);

if (active_net == 0){
printf(ALG_CENTER, "NO Active net work");
server_socket = tcp_server(SERVER_PORT, 1);
if (iserver_socket >=0){
printf(ALG_LEFT, "Wait connection on %d...", SERVER_PORT);
After this, it should go to next step but it is failing to do so,

while (1){
if (kb_hit()){
if (0x1B == kb_getkey())
iclient_socket = tcp_accept(iserver_socket, client_addr, &client_port);
if (iclient_socket < 0)
else {
printf(ALG_LEFT, "Connected from %s:%d...", client_addr, client_port);
inet_ntoa(((structsockaddr_in*)&ifr.ifr_addr)->sin_addr), SERVER_PORT);
I am confused in this step. could you give clear meaning of this step?


This is my client tcp ip program, It is showing connection failed, how it can be resolved? I am giving working server ip address and port number.

void socket_client_demo(void)
int iclient_socket = -1;
unsigned char bTemp[1024];
unsigned int iTemp;
printf(ALG_CENTER, "socket client");
printf(ALG_LEFT, "connect to %s:%d...", SERVER_ADDR, SERVER_PORT);
iclient_socket = tcp_connect(SERVER_ADDR, SERVER_PORT);
if (iclient_socket < 0){
lcd_printf(ALG_LEFT, "Connect failed.");
After this step i need to go for
}else {
while (1){
if (kb_hit()){
if (0x1B == kb_getkey())
strcpy((char*)bTemp, "HELLO WORLD");
iTemp = strlen((char*)bTemp);
if (tcp_write(iclient_socket , bTemp, iTemp) < 0)
// next step tcp write and tcp read
Old 03-16-2014, 02:21 AM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
Highly recommended
1 members found this post helpful.
Old 03-16-2014, 02:51 AM   #3
parvathi reddy
LQ Newbie
Registered: Mar 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
tcp ip socket- server program

how to resolve this issue...

thanks in advance


socket, tcpip

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] TCP File Transfer in C with socket (server/client) on Linux. Help with code AscaL Programming 14 07-07-2015 01:46 PM
Client TCP socket recv returning 0 when server closes the connection dfbloemen Programming 3 06-21-2012 09:24 AM
Client Server Socket TCP/IP program in C Linux over HTTPS fahad.anwar Linux - Newbie 6 05-29-2012 03:59 AM
Client Server Socket TCP/IP program in C Linux using threads fahad.anwar Linux - Newbie 2 05-18-2012 04:34 AM
[SOLVED] How could server detect closed client socket using TCP and c++? Lobinho Programming 6 08-10-2010 02:28 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration