473,414 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Socket Problem............

Please help me.......
I am getting blocked in bind() system call.......

i don't know why

can you please any one tell me why........
#include<stdio.h>
#include<sys/un.h>
#include<sys/types.h>
#include<sys/socket.h>
#define SOCK_PATH "mysock1"
void error(char *);
main()
{
printf("OK");
int sockfd,newsockfd,serverlen,clilen,n;
struct sockaddr_un cli_addr,serv_addr;
char buf[80];
printf("Ok");
if((sockfd=socket(AF_UNIX,SOCK_STREAM,0))<0)
perror("creating socket");
serv_addr.sun_family=AF_UNIX;
printf("OK");
unlink(SOCK_PATH);
strcpy(serv_addr.sun_path,SOCK_PATH);
if(bind(sockfd,(struct sockaddr
*)&serv_addr,sizeof(serv_addr))<0)
perror("binding socket");
listen(sockfd,1);
clilen=sizeof(cli_addr);
newsockfd=accept(sockfd,(struct sockaddr
*)&cli_addr,&clilen);
printf("Ok\n");
if(newsockfd<0)
error("accepting");
for(;;)
{
printf("Waiting for Client......\n");
read(newsockfd,buf,sizeof(buf));
printf("**CLIENT** :%s",buf);
if(strcmp("end\n",buf)==0)
{
printf("Disconnecting\n");
exit(0);
}
printf("**SERVER** :");
fgets(buf,sizeof(buf),stdin);
write(newsockfd,buf,sizeof(buf));
}
}
void error(char *msg)
{
perror(msg);
exit(0);
}

Oct 19 '07 #1
3 1752
Clement wrote:
Please help me.......
I am getting blocked in bind() system call.......

i don't know why

can you please any one tell me why........
<snip>

Since bind() is not defined by ISO C, you should try a group specific to
your system, most likely <comp.unix.programmer>

Oct 19 '07 #2
On Oct 19, 2:12 pm, Clement <jeba.r...@gmail.comwrote:
Please help me.......
I am getting blocked in bind() system call.......

i don't know why

can you please any one tell me why........

#include<stdio.h>
#include<sys/un.h>
#include<sys/types.h>
#include<sys/socket.h>
#define SOCK_PATH "mysock1"
void error(char *);
main()
{
printf("OK");
int sockfd,newsockfd,serverlen,clilen,n;
struct sockaddr_un cli_addr,serv_addr;
char buf[80];
printf("Ok");
if((sockfd=socket(AF_UNIX,SOCK_STREAM,0))<0)
perror("creating socket");
serv_addr.sun_family=AF_UNIX;
printf("OK");
unlink(SOCK_PATH);
strcpy(serv_addr.sun_path,SOCK_PATH);
if(bind(sockfd,(struct sockaddr
*)&serv_addr,sizeof(serv_addr))<0)
perror("binding socket");
listen(sockfd,1);
clilen=sizeof(cli_addr);
newsockfd=accept(sockfd,(struct sockaddr
*)&cli_addr,&clilen);
printf("Ok\n");
if(newsockfd<0)
error("accepting");
for(;;)
{
printf("Waiting for Client......\n");
read(newsockfd,buf,sizeof(buf));
printf("**CLIENT** :%s",buf);
if(strcmp("end\n",buf)==0)
{
printf("Disconnecting\n");
exit(0);
}
printf("**SERVER** :");
fgets(buf,sizeof(buf),stdin);
write(newsockfd,buf,sizeof(buf));
}}

void error(char *msg)
{
perror(msg);
exit(0);

}- Hide quoted text -

- Show quoted text -
Try configuring your socket for non-blocking (i.e. asynchronous)
operation prior to calling the bind function. This will allow you to
place a timeout on the bind() call which will return some type of
error code instead of just hanging your system. You can then review
this error code to determine what the problem is. Don't forget to
change the socket back to blocking.

Keith
http://www.doubleblackdesign.com

Oct 20 '07 #3
Clement wrote:
>
I am getting blocked in bind() system call.......
i don't know why
can you please any one tell me why........

#include<stdio.h>
#include<sys/un.h>
#include<sys/types.h>
#include<sys/socket.h>
So far the only thing mentioned that exists in standard C is
<stdio.h>. Try a newsgroup that deals with your particular
system.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Oct 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Thomas Hervé | last post by:
My problem is not really python specific but as I do my implementation in python I hope someone here can help me. I have two programs that talk through a socket. Here is the code : <server>...
4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
4
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
16
by: =?iso-8859-1?q?|-|e|=5F|=5F_B0=DD?= | last post by:
hi all! I got a problem. I declared a SOCKET var in my C program but when i compiled the program it displayed like *--------------------------------------------------------------* *'SOCKET':...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.