473,799 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,newsockf d,serverlen,cli len,n;
struct sockaddr_un cli_addr,serv_a ddr;
char buf[80];
printf("Ok");
if((sockfd=sock et(AF_UNIX,SOCK _STREAM,0))<0)
perror("creatin g socket");
serv_addr.sun_f amily=AF_UNIX;
printf("OK");
unlink(SOCK_PAT H);
strcpy(serv_add r.sun_path,SOCK _PATH);
if(bind(sockfd, (struct sockaddr
*)&serv_addr,si zeof(serv_addr) )<0)
perror("binding socket");
listen(sockfd,1 );
clilen=sizeof(c li_addr);
newsockfd=accep t(sockfd,(struc t sockaddr
*)&cli_addr,&cl ilen);
printf("Ok\n");
if(newsockfd<0)
error("acceptin g");
for(;;)
{
printf("Waiting for Client......\n" );
read(newsockfd, buf,sizeof(buf) );
printf("**CLIEN T** :%s",buf);
if(strcmp("end\ n",buf)==0)
{
printf("Disconn ecting\n");
exit(0);
}
printf("**SERVE R** :");
fgets(buf,sizeo f(buf),stdin);
write(newsockfd ,buf,sizeof(buf ));
}
}
void error(char *msg)
{
perror(msg);
exit(0);
}

Oct 19 '07 #1
3 1791
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.prog rammer>

Oct 19 '07 #2
On Oct 19, 2:12 pm, Clement <jeba.r...@gmai l.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,newsockf d,serverlen,cli len,n;
struct sockaddr_un cli_addr,serv_a ddr;
char buf[80];
printf("Ok");
if((sockfd=sock et(AF_UNIX,SOCK _STREAM,0))<0)
perror("creatin g socket");
serv_addr.sun_f amily=AF_UNIX;
printf("OK");
unlink(SOCK_PAT H);
strcpy(serv_add r.sun_path,SOCK _PATH);
if(bind(sockfd, (struct sockaddr
*)&serv_addr,si zeof(serv_addr) )<0)
perror("binding socket");
listen(sockfd,1 );
clilen=sizeof(c li_addr);
newsockfd=accep t(sockfd,(struc t sockaddr
*)&cli_addr,&cl ilen);
printf("Ok\n");
if(newsockfd<0)
error("acceptin g");
for(;;)
{
printf("Waiting for Client......\n" );
read(newsockfd, buf,sizeof(buf) );
printf("**CLIEN T** :%s",buf);
if(strcmp("end\ n",buf)==0)
{
printf("Disconn ecting\n");
exit(0);
}
printf("**SERVE R** :");
fgets(buf,sizeo f(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
2655
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> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.settimeout(5.0)
4
11781
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
2274
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 point. System.Net.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr); System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
4
7091
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 incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
4
18138
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 as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call shutdown and close asynchronously if possible.
4
2352
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
8619
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 mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
6
3678
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 windows and linux. so I guess there is a problem with makefile(). # Echo server program
0
3588
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but actual files that are sent to the computer as part of http or ftp. Basically if a user browse a page...
16
3860
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': illegal use of this type as an expression * * C:\..\..\..\include\winsock2.h: see declaration of 'SOCKET' * *--------------------------------------------------------------* What i wrote in my program is like this..:
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.