Re: Connect call fails.
amitraj.trehan_at_gmail.com
Date: 04/27/05
- Next message: Heiko: "Re: How to check if dir is NFS mounted?"
- Previous message: Frederick Bruckman: "Re: Obtaining STD time on BSD/Darwin"
- In reply to: Barry Margolin: "Re: Connect call fails."
- Next in thread: James Antill: "Re: Connect call fails."
- Reply: James Antill: "Re: Connect call fails."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Apr 2005 07:56:31 -0700
Thanks for your reply. I have the same error even if I have my server
running. Here is the server code.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
int main(int argc, char* const argv[])
{
int socket_fd, client_sock_fd;
int bytes_read, length;
struct sockaddr_un name;
const char* const socket_name = argv[1];
socket_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
name.sun_family = AF_LOCAL;
strcpy(name.sun_path, socket_name);
if (bind(socket_fd, (struct sockaddr*)&name, SUN_LEN(&name)) <
0)
printf("Error\n");
listen(socket_fd, 5);
while(1)
{
char *msg;
struct sockaddr_un client;
socklen_t client_len;
client_sock_fd = accept (socket_fd, (struct
sockaddr*)&client, &client_len);
bytes_read = read(client_sock_fd, &length,
sizeof(length));
if (bytes_read >0)
printf("%d", bytes_read);
msg = (char*) malloc (length);
read(client_sock_fd,msg, length);
printf("%s", msg);
}
close(socket_fd);
unlink(socket_name);
return 0;
}
Barry Margolin wrote:
> In article <1114572274.076660.142900@f14g2000cwb.googlegroups.com>,
> amitraj.trehan@gmail.com wrote:
>
> > Hi,
> > I am writing my first socket program and I am getting the error 111
> > (Connection refused). Can someone please tell me what am I doing
wrong
> > in the program.
> >
> > When i run the client program without running the server, the
connect
> > call still fails. I would really appreciate your help.
>
> That's to be expected. You can't connect to a socket if there's no
> server listening for connections.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
- Next message: Heiko: "Re: How to check if dir is NFS mounted?"
- Previous message: Frederick Bruckman: "Re: Obtaining STD time on BSD/Darwin"
- In reply to: Barry Margolin: "Re: Connect call fails."
- Next in thread: James Antill: "Re: Connect call fails."
- Reply: James Antill: "Re: Connect call fails."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|