LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-16-2014, 12:59 AM   #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 127.0.0.1 and it is Waiting on (1978=port number) i.e., "connection on %d...", SERVER_PORT.

Quote:
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);
active_net++;
}}

if (active_net == 0){
printf(ALG_CENTER, "NO Active net work");
kb_getkey();
return;}
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,

Quote:
while (1){
if (kb_hit()){
if (0x1B == kb_getkey())
break;
}
iclient_socket = tcp_accept(iserver_socket, client_addr, &client_port);
if (iclient_socket < 0)
continue;
else {
printf(ALG_LEFT, "Connected from %s:%d...", client_addr, client_port);
Quote:
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?



TCP IP SOCKET CLIENT SAMPLE PROGRAM


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.

Quote:
void socket_client_demo(void)
{
int iclient_socket = -1;
unsigned char bTemp[1024];
unsigned int iTemp;
clean();
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
Quote:
kb_getkey();
}else {
while (1){
if (kb_hit()){
if (0x1B == kb_getkey())
break;}
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, 03:21 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Highly recommended http://beej.us/guide/bgnet/
 
1 members found this post helpful.
Old 03-16-2014, 03: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
 
  


Reply

Tags
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 02:46 PM
Client TCP socket recv returning 0 when server closes the connection dfbloemen Programming 3 06-21-2012 10:24 AM
Client Server Socket TCP/IP program in C Linux over HTTPS fahad.anwar Linux - Newbie 6 05-29-2012 04:59 AM
Client Server Socket TCP/IP program in C Linux using threads fahad.anwar Linux - Newbie 2 05-18-2012 05:34 AM
[SOLVED] How could server detect closed client socket using TCP and c++? Lobinho Programming 6 08-10-2010 03:28 PM


All times are GMT -5. The time now is 05:13 AM.

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