Thread View: pl.comp.os.linux.programowanie
5 messages
5 total messages
Started by miron123
Tue, 08 Mar 2011 12:12
sockety z problemami
Author: miron123
Date: Tue, 08 Mar 2011 12:12
Date: Tue, 08 Mar 2011 12:12
65 lines
2744 bytes
2744 bytes
Mam nastepujacy kod:
int main(int argc, char *argv[])
{
int socket_fd;
struct sockaddr_un name;
int sent, length;
socket_fd=socket(PF_LOCAL,SOCK_STREAM,0);
name.sun_family=AF_LOCAL;
strcpy(name.sun_path,argv[1]);
if(connect(socket_fd,(struct
sockaddr*)&name,SUN_LEN(&name))==-1)
error("Error during connecting");
printf("%s\n",argv[2]);
length=strlen(argv[2])+1;
printf("%s %d %d\n",argv[2],length,sizeof(length));
sent=write(socket_fd,&length,sizeof(length));
if (sent==-1)
error("Error during writeing to socket");
else if (sent<length)
printf("%s\n","Not everything was sent");
printf("%s %d %d\n",argv[2],length,sizeof(length));
sent=write(socket_fd,argv[2],length);
if (sent==-1)
error("Error during writeing to socket");
else if (sent<length)
printf("%s\n","Not everything was sent");
printf("%s %d %d %d\n",argv[2],length,sizeof(length),sent);
printf("%s\n","done");
close(socket_fd);
return 0;
}
Mam uruchomiony server, ktory czyta z socketa, ktorym jest /tmp/
socket
zatem uruchomienie powyższego powinno wygladac:
$> ./socket-client /tmp/socket napis
napis
napis 6 4
napis 6 4
napis 6 4 6
done
$>
a wyglada
$> ./socket-client /tmp/socket napis
napis
napis 6 4
$>
wyglada to jakby zatrzymywal sie na drugim write. O co tu chodzi?
Uruchomienie w gdb daje dobry rezultat, co powoduje, ze ja juz nic nie
rozumiem.
Czy ktos mogbly mnie olsnic, lub chociaz naprowadzic gdzie jest blad?
Re: sockety z problemami
Author: Adam Osuchowski
Date: Tue, 08 Mar 2011 15:26
Date: Tue, 08 Mar 2011 15:26
13 lines
1430 bytes
1430 bytes
miron123@go2.pl wrote: > wyglada to jakby zatrzymywal sie na drugim write. O co tu chodzi? > Uruchomienie w gdb daje dobry rezultat, co powoduje, ze ja juz nic nie > rozumiem. > > Czy ktos mogbly mnie olsnic, lub chociaz naprowadzic gdzie jest blad? A co słucha po drugiej stronie na sockecie? U mnie wysłał wszystko z dokładnością do tego, że napisał ,,Not everything was sent'' bo zamiast sprawdzać czy sent < sizeof(length), sprawdzasz czy sent < length. Puść strace'a na niego i zobacz na czym dokładnie wisi i co robi w tym samym momencie proces nasłuchujący na sockecie.
Re: sockety z problemami
Author: miron123
Date: Tue, 08 Mar 2011 19:23
Date: Tue, 08 Mar 2011 19:23
3 lines
1321 bytes
1321 bytes
Jest to wogole dziwne. Ten kod pod slackware chodzi bez zajakniecia, a pod opensuse sie buzy. No nic, trzeba bedzie sie guru od suse podpytac.
Re: sockety z problemami
Author: Adam Wysocki
Date: Wed, 09 Mar 2011 22:47
Date: Wed, 09 Mar 2011 22:47
13 lines
1695 bytes
1695 bytes
miron123@go2.pl <miron123@go2.pl> wrote: > Mam uruchomiony server, ktory czyta z socketa, ktorym jest /tmp/ > socket Jaki to serwer? Jakiś Twój? Zainstaluj program socat i uruchom tak: socat unix-listen:/tmp/socket stdio -- gof
Re: sockety z problemami
Author: Adam Wysocki
Date: Wed, 09 Mar 2011 22:47
Date: Wed, 09 Mar 2011 22:47
15 lines
1734 bytes
1734 bytes
miron123@go2.pl <miron123@go2.pl> wrote: > Mam uruchomiony server, ktory czyta z socketa, ktorym jest /tmp/ > socket Jaki to serwer? Jakiś Twój? Zainstaluj program socat i uruchom: socat unix-listen:/tmp/socket stdio To pozwoli wykluczyć problem z serwerem. -- gof
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads