Unix Programming - EILSEQ error in socket

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2006 > EILSEQ error in socket





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author EILSEQ error in socket
karthikeyan.jambulingam@gmail.com

2006-04-27, 7:55 am

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

sweety.rathore@gmail.com

2006-04-27, 7:55 am

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

karthikeyan.jambulingam@gmail.com

2006-04-27, 7:55 am

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

Nils O. Selåsdal

2006-04-27, 7:55 am

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 ?
karthikeyan.jambulingam@gmail.com

2006-04-27, 7:55 am

Hi,

Yes I use the plain write(2) call.

Regards
JK

Nils O. Selåsdal

2006-04-27, 7:55 am

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.
karthikeyan.jambulingam@gmail.com

2006-04-27, 7:56 am

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

Nils O. Selåsdal

2006-04-27, 7:56 am

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.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com