LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-20-2009, 01:08 AM   #1
muchala123
LQ Newbie
 
Registered: Feb 2009
Posts: 2
Blog Entries: 1

Rep: Reputation: 0
socket programming


hello,
i have a doubt in socket programming..

i wrote a client socket program..and a server program..

in client program,,after creating a socket using socket system call,i did few things required for my program not related to socket..

after that i prepared the structures required for the socket,i used connect system call.

when i am running these two programs,i am getting error as unable to connect.i found that connect is returning -1..

but the same program when i put connect system call immediately after socket system call without doing anything other it is working fine?

please tell what might be the reason for it?
 
Old 02-20-2009, 02:22 AM   #2
vkmgeek
Member
 
Registered: Feb 2006
Location: Ahmedabad
Distribution: rhel5
Posts: 185
Blog Entries: 2

Rep: Reputation: 31
depends on "wht other" you are doing ?
post code if possible
 
Old 02-20-2009, 02:32 AM   #3
muchala123
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Quote:
Originally Posted by vkmgeek View Post
depends on "wht other" you are doing ?
post code if possible

client program:

struct sockaddr_in s1;

for(index1=0;configstring[index1]!=':';index1++)
{
address[index1] = configstring[index1];
}
address[index1++]='\0';

for(index2=0;configstring[index1]!='\0';index1++,index2++)
{
port[index2] = configstring[index1];

}
port[index2++]='\0';
printf("%s\n%s\n",address,port);
int port_num = changeto_int(port);

if((sock_fd = socket(AF_INET,SOCK_STREAM,0)) == -1)
{
printf("unable to create a socket\n");
return 0;
}
printf("%d\n",sock_fd);

s1.sin_family=AF_INET;
s1.sin_port=htons(7010);
s1.sin_addr.s_addr=inet_addr(address);
memset(s1.sin_zero, '\0', sizeof s1.sin_zero);


if(connect(sock_fd,(struct sockaddr *)&s1,sizeof(s1)) == -1)
{
printf("error:unable to connect\n");
return -1;
}

like this if i do it is coming....but if the for loops are kept at below socket system call and above preparing that socket structures,then it is printing it is unable to connect..pls see it and tell me
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Programming ashley_31 Linux - Software 2 06-05-2006 02:30 AM
Socket Programming jawadhashmi Programming 4 05-24-2005 03:04 AM
Socket Programming Chaitanyayardi Programming 6 10-22-2004 12:10 AM
socket programming???? harbir Linux - Networking 2 07-05-2004 02:52 AM
Socket Programming cxel91a Programming 4 03-19-2003 10:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:31 PM.

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
Open Source Consulting | Domain Registration