[x] Welcome to LinuxSolved.com Linux help forums, here we are a community of Linux users helping each other. It is helpful to both ie. new linux users as well experienced one. We always have our experts to help you and ofcourse members help each other, so you can ask for help any time by Registering.: Click to Register

Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Linux Forums - Linux Help,Advice & support community:LinuxSolved.com  |  Forum  |  Linux in General  |  Linux Development & Programming  |  Topic: Socket Programming Problem
The LinuxSolved.com GNU/Linux User Communit - Forum
Welcome to LinuxCommunity You have just arrived to a friendly linux community which is helping Linux Users from Years.. You can be its part if you have not already joined it. Registration is FREE and is gateway to unlimited help and support to all your linux related needs. If you are an GNU/Linux supporter then you have come to the right place.
Pages: [1]
  Print  
Author Topic: Socket Programming Problem  (Read 297 times)
0 Members and 1 Guest are viewing this topic.
docfan
New Member

Offline Offline

Posts: 1


View Profile
« on: February 26, 2008, 01:38:44 PM »

Hi,

I am programming a simple chat server in C.
I use asynchronous TCP socket to receive data from clients which are on Win32 system.

The problem is that when the application on Win32 is close or disconnect from server (by closesocket()),
the server will display a message "pollable event" and quit.

It seems that it receive SIGPIPE signal as I am searching on the Internet to figure out the reason.

Can anyone tell me how I can fix this problem so that the server will not close automatically?
Thank you very much
------------------------------------------------------
Here is my part of code.

void* TCPThread(void *arg)
{

   int tcpid[MAXUSER];
   int len;
   int index;
   int fileflags;
   struct sockaddr_in tcp_addr[MAXUSER];
   void sig_io(int sig);

   fprintf(stderr, "TCP thread Start\n");
   index=0;
   len=sizeof(tcp_addr[index]);

   for( ; ; )
   {
      bzero((char *) tcp_addr+index,sizeof(tcp_addr[index]));
      tcpid[index]=accept(sock_tcp, (struct sockaddr*) tcp_addr+index, &len);
      printaddr(&tcp_addr[index]);
      index++;
      index= index & MAXUSER;

      fileflags  = fcntl(tcpid[index], F_GETFL );
      if (fileflags  == -1)
         perror("fcntl F_GETFL");

      if (fcntl(tcpid[index], F_SETFL, fileflags | FNDELAY | FASYNC) < 0)
         fprintf(stderr, "%d TCP Socket Asyn Error", index);
      if (fcntl(tcpid[index], F_SETOWN, getpid()) <0)
         fprintf(stderr, "Can't own SIGIO");

      signal(SIGIO, sig_io);
   }

   pthread_exit(NULL);
}

void sig_io(int sig)
{
   char msg[MAXMESG];
   recv(tcpid[0], msg, sizeof(msg), 0);
   fprintf(stderr, msg);
}
Logged
Linux Forums - Linux Help,Advice & support community:LinuxSolved.com
   

 Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Network programming Linux Development & Programming bahram741413 4 1446 Last post April 17, 2004, 12:05:12 PM
by sudipta_cht
Programming [W5H Series] Linux Development & Programming JPushkarH 3 1186 Last post September 11, 2004, 01:57:03 AM
by JPushkarH
ethernet socket Linux Development & Programming mrsinghal 1 1262 Last post October 07, 2005, 01:28:41 PM
by misterscorp
C Programming In Linux---Big problem Linux Development & Programming shobhit143 3 1217 Last post October 08, 2005, 02:57:11 AM
by deven_01
raw socket General Networking Support in Linux kqclinux 0 487 Last post November 14, 2005, 03:53:33 PM
by kqclinux
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2008, 09:33:44 AM

Login with username, password and session length
Navigation
Recent Discussions
[November 20, 2008, 11:30:52 PM]

[November 19, 2008, 07:52:41 PM]

[November 19, 2008, 07:52:36 PM]

[November 17, 2008, 10:42:59 AM]

[November 16, 2008, 12:49:47 AM]

[November 16, 2008, 12:48:58 AM]

[November 15, 2008, 08:29:02 AM]

[November 15, 2008, 08:24:41 AM]

[November 14, 2008, 05:11:50 AM]

[November 13, 2008, 03:28:22 AM]
Members
Total Members: 6227
Latest: karunadct
Stats
Total Posts: 8269
Total Topics: 2253
Online Today: 10
Online Ever: 111
(June 28, 2007, 06:47:29 AM)
Users Online
Users: 0
Guests: 11
Total: 11
Privacy Policy| Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks
Theme & TinyPortal v0.9.8 © Bloc