EILSEQ error in socket
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > EILSEQ error in socket




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    EILSEQ error in socket  
karthikeyan.jambulingam@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

Dear all,

I am getting an EILSEQ error while trying to write a sequence of
character into a socket using "write" function. From man pages i found
that this error indicates "Illegal byte sequence" . This error is not
frequent and occurs at times. This is the message iam trying to write
"\r\nabc>". How should i proceed further , i dont have any idea about
this error and has not encountered it before.

What does this error specify , is this related to OS or should i debug
my code ? I am using Red Hat Linux 9.0.

Thanks
JK






[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
sweety.rathore@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

Dear karthikeyan,
I think there is absolutely no problem writing this sequence on the
socket...
Its working fine..here is the code--

CLIENT--
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<stdio.h>
main(int argc, char **argv)
{
struct sockaddr_in servaddr;
int sockfd,connfd;
char buffer[1024];
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd <0 )
{
printf("socket not created");
}

bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(14000);
inet_pton(AF_INET,argv[1],&servaddr.sin_addr);
if(connect(sockfd,(struct
sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("No connection exists to server\n");

sprintf(buffer,"%s","\r\nabc>");
write(sockfd,buffer,1024);
}

SERVER--
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<stdio.h>
main(int argc, char **argv)
{
struct sockaddr_in servaddr;
int sockfd, connfd,len;
char buff[1024];
sockfd=socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(14000);
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sockfd,(struct sockaddr*)
&servaddr,sizeof(servaddr))<0)
printf("binding error\n");
listen(sockfd,5);
for(;;)
{
connfd=accept(sockfd,NULL,NULL);
read(connfd,buff,1024);
len=strlen(buff);
write(1,buff,len);
}
}

Thanks
SR






[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
karthikeyan.jambulingam@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

Dear SR,

Thanks for your reply. My application is a multi threaded one that
manages a lot of servers and their respective client connections. It is
not the string which iam writing up is causing the problem , there is
something else (either hardware related or OS related) which is causing
this problem.

Still searching out ways why this problem is caused in RedHat Linux ,
when the same code works in Debian Linux. Is there any one who has
encountered this error ??

Regards
JK


Regards
JK






[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
Nils O. Selåsdal


Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

karthikeyan.jambulingam@gmail.com wrote:
> Dear SR,
>
> Thanks for your reply. My application is a multi threaded one that
> manages a lot of servers and their respective client connections. It is
> not the string which iam writing up is causing the problem , there is
> something else (either hardware related or OS related) which is causing
> this problem.
>
> Still searching out ways why this problem is caused in RedHat Linux ,
> when the same code works in Debian Linux. Is there any one who has
> encountered this error ??
How do you write the bytes to the socket ? Plain write(2) call ?





[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
karthikeyan.jambulingam@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

Hi,

Yes I use the plain write(2) call.

Regards
JK






[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
Nils O. Selåsdal


Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:55 PM

karthikeyan.jambulingam@gmail.com wrote:
> Hi,
>
> Yes I use the plain write(2) call.
That should not give that error.
Be sure you don't do something like
ret = write(...);
if(ret == -1) {
printf(something);
perror("write failed");
}

or otherwise do any output or other calls before you
inspect errno.





[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
karthikeyan.jambulingam@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

Hi,

Sorry, I am not able to get your point. What are you stating not to do.
This is how my code is
while (mesgLen && !(retVal < 0))
{
retVal = write(clientSocket, mesgBuf, mesgLen);
mesgLen -= retVal;
}
next to this i check for errnos and print them. Is there any issue in
this !.

Regards
JK






[ Post a follow-up to this message ]



    Re: EILSEQ error in socket  
Nils O. Selåsdal


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

On Wed, 19 Apr 2006 21:40:29 -0700, karthikeyan.jambulingam@gmail.com
wrote:

> Hi,
>
> Sorry, I am not able to get your point. What are you stating not to do.
> This is how my code is
> while (mesgLen && !(retVal < 0))
>  {
>        retVal = write(clientSocket, mesgBuf, mesgLen);
>        mesgLen -= retVal;
>   }
> next to this i check for errnos and print them. Is there any issue in
> this !.
yes. you have to atleast check that the write call succeeded on
each iteration.
Secondly, you shall NOT inspect errno unless a call actually errors.

while (mesgLen && !(retVal < 0))
{
retVal = write(clientSocket, mesgBuf, mesgLen);
if(retVal == -1) { /* Now it is ok to inspect errno */
perror("write failed");
return;/*bail out , or whatever */
}
mesgLen -= retVal;
}

after this, do not check errno unless write actually failed.
If everything is ok, errno is not guaranteed to have the value 0.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:46 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register