socket communication problems

sekoppenhoef at rose.waterloo.edu sekoppenhoef at rose.waterloo.edu
Mon Sep 18 01:48:33 AEST 1989


Can anyone help me here? I thought that SOCK_STREAM type sockets were
bidirectional in communication. Shouldn't I be able to read and write on
BOTH ends of a socket connection? The following code is part of the client
end. I want the client to get and receive info from a server. So *both*
sides need to read and write. What am i doing wrong?


	sock = socket(AF_INET, SOCK_STREAM, 0);
		.
		.
	server.sin_family = AF_INET;
	hp = gethostbyname(argv[1]);
		.
		.
	bcopy( hp->h_addr, &server.sin_addr, hp->h_length); 
	server.sin_port = htons(atoi(argv[2]));
	
	if (connect(sock, &server, sizeof(server)) < 0){
		perror("connecting to stream socket"); exit(1);
		}

**These two commands are what I'm using to write and read... the 'write' works
**on the client end but not the read, and vice versa for the server end
the server end uses an ACCEPT to get the scket name for communication of course.
		
	write(sock, buf, n) 
	read(sock,buf,sizeof(buf) ) 


HELP!


	



More information about the Comp.unix.wizards mailing list