Server No such file or directory [on hold]











up vote
0
down vote

favorite












I have a problem with connecting client to server in this code. It worked, but I made some changes and I can't connect to server anymore.



echoServer.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include <ctype.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ;

int server_sockfd = -1 ;
int client_sockfd = -1 ;

void cleanup( void ){
if( server_sockfd != -1 ){
close( server_sockfd ) ;
server_sockfd = -1 ;
}
if( client_sockfd != -1 ){
close( client_sockfd ) ;
client_sockfd = -1 ;
}
}

//converts string to upper case
int strToUpper( char *str , int size ){
int i = 0 ;

while( *str != '' && i++ < size ){
*str = toupper( *str ) ;
str++ ;
}
return i ;
}

int main( int argc, const char *argv ){

int len ;
int client_len ;

//local sockets
struct sockaddr_un server_address ;
struct sockaddr_un client_address ;

atexit( cleanup ) ;

//remove old sockets with same name as specified
unlink(SERVER_ADDRESS);

//create socket
_runSafe(server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0));

//bind a name to socket
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, SERVER_ADDRESS);

_runSafe(bind(server_sockfd, (struct sockaddr *) &server_address , sizeof(server_address)));

//start listening on the named socket
_runSafe(listen(server_sockfd, 10));

while( 1 ) {
memset(Buff, 0, sizeof(Buff));
printf("Server waiting.n") ;

//accept incomming client connection
_runSafe(client_sockfd = accept(server_sockfd, (struct sockaddr*) &client_address, &client_len));

//read message from client
_runSafe(read(client_sockfd, Buff, MAX_MSG_SIZE));
//convert client's message to upper case and reply to client
strToUpper(Buff, sizeof(Buff));
_runSafe(write(client_sockfd, Buff, strlen(Buff)));

//close temporary socket
close( client_sockfd ) ;
client_sockfd = -1 ;

memset(Buff, 0, sizeof(Buff));
}

//program will never reach this point
return 0 ;
}


echoClient.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ; // output message buffer
char Fubb[ MAX_MSG_SIZE ] ; // input message buffer

int Sock_fd = -1 ;

void cleanup( void ){
if( Sock_fd != -1 ){
close( Sock_fd ) ;
Sock_fd = -1 ;
}
}

//client code
int main( int argc, const char *argv ){

int len ;
struct sockaddr_un address ; //this is for local sockets
int result ;

strcpy(Buff, argv[1]);

atexit( cleanup ) ;

//create unnamed socket
_runSafe(Sock_fd = socket(AF_UNIX, SOCK_STREAM, 0));

//set server socket name
address.sun_family = AF_UNIX;
strcpy(address.sun_path, SERVER_ADDRESS);

//connect to server
_runSafe(connect(Sock_fd, (struct sockaddr *) &address, sizeof(address)));
printf("client sending message:%sn", Buff ) ;

//write to socket
_runSafe(write(Sock_fd, Buff, strlen(Buff)));

//read answer from socket
_runSafe(read(Sock_fd, Fubb, MAX_MSG_SIZE));

//show server reply to user
printf("client received reply from server:%sn", Fubb ) ;

//close connection
close( Sock_fd ) ;
Sock_fd = -1 ;

return 0 ;
}


Some settings



    #ifndef _SETTINGS
#define _SETTINGS 1

//some common settings for client and server programs

#define MAX_MSG_SIZE 255 //
#define SERVER_ADDRESS "server_socket" // filename for local sockets

//use the folowing macro for error checking

static char _errBuf[ 1024 ] ;

#define _runSafe( code ) if((code) == -1){
sprintf( _errBuf, "Error in: %s on line: %d:", __FILE__, __LINE__ ) ;
perror( _errBuf ) ;
exit( 1 ) ;
}

#endif


Compiled



gcc echoServer.c -o server
gcc echoClient.c -o client
server


...and in second terminal...



client hello
Error in: echoClient.c on line: 58:: No such file or directory









share|improve this question







New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Scott, RalfFriedl, Thomas, Kusalananda, Jeff Schaller Nov 27 at 10:44


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • when the parameters to main() are not going to be used, then use the signature: int main( void )
    – user3629249
    Nov 27 at 7:23










  • this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
    – user3629249
    Nov 27 at 7:32















up vote
0
down vote

favorite












I have a problem with connecting client to server in this code. It worked, but I made some changes and I can't connect to server anymore.



echoServer.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include <ctype.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ;

int server_sockfd = -1 ;
int client_sockfd = -1 ;

void cleanup( void ){
if( server_sockfd != -1 ){
close( server_sockfd ) ;
server_sockfd = -1 ;
}
if( client_sockfd != -1 ){
close( client_sockfd ) ;
client_sockfd = -1 ;
}
}

//converts string to upper case
int strToUpper( char *str , int size ){
int i = 0 ;

while( *str != '' && i++ < size ){
*str = toupper( *str ) ;
str++ ;
}
return i ;
}

int main( int argc, const char *argv ){

int len ;
int client_len ;

//local sockets
struct sockaddr_un server_address ;
struct sockaddr_un client_address ;

atexit( cleanup ) ;

//remove old sockets with same name as specified
unlink(SERVER_ADDRESS);

//create socket
_runSafe(server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0));

//bind a name to socket
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, SERVER_ADDRESS);

_runSafe(bind(server_sockfd, (struct sockaddr *) &server_address , sizeof(server_address)));

//start listening on the named socket
_runSafe(listen(server_sockfd, 10));

while( 1 ) {
memset(Buff, 0, sizeof(Buff));
printf("Server waiting.n") ;

//accept incomming client connection
_runSafe(client_sockfd = accept(server_sockfd, (struct sockaddr*) &client_address, &client_len));

//read message from client
_runSafe(read(client_sockfd, Buff, MAX_MSG_SIZE));
//convert client's message to upper case and reply to client
strToUpper(Buff, sizeof(Buff));
_runSafe(write(client_sockfd, Buff, strlen(Buff)));

//close temporary socket
close( client_sockfd ) ;
client_sockfd = -1 ;

memset(Buff, 0, sizeof(Buff));
}

//program will never reach this point
return 0 ;
}


echoClient.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ; // output message buffer
char Fubb[ MAX_MSG_SIZE ] ; // input message buffer

int Sock_fd = -1 ;

void cleanup( void ){
if( Sock_fd != -1 ){
close( Sock_fd ) ;
Sock_fd = -1 ;
}
}

//client code
int main( int argc, const char *argv ){

int len ;
struct sockaddr_un address ; //this is for local sockets
int result ;

strcpy(Buff, argv[1]);

atexit( cleanup ) ;

//create unnamed socket
_runSafe(Sock_fd = socket(AF_UNIX, SOCK_STREAM, 0));

//set server socket name
address.sun_family = AF_UNIX;
strcpy(address.sun_path, SERVER_ADDRESS);

//connect to server
_runSafe(connect(Sock_fd, (struct sockaddr *) &address, sizeof(address)));
printf("client sending message:%sn", Buff ) ;

//write to socket
_runSafe(write(Sock_fd, Buff, strlen(Buff)));

//read answer from socket
_runSafe(read(Sock_fd, Fubb, MAX_MSG_SIZE));

//show server reply to user
printf("client received reply from server:%sn", Fubb ) ;

//close connection
close( Sock_fd ) ;
Sock_fd = -1 ;

return 0 ;
}


Some settings



    #ifndef _SETTINGS
#define _SETTINGS 1

//some common settings for client and server programs

#define MAX_MSG_SIZE 255 //
#define SERVER_ADDRESS "server_socket" // filename for local sockets

//use the folowing macro for error checking

static char _errBuf[ 1024 ] ;

#define _runSafe( code ) if((code) == -1){
sprintf( _errBuf, "Error in: %s on line: %d:", __FILE__, __LINE__ ) ;
perror( _errBuf ) ;
exit( 1 ) ;
}

#endif


Compiled



gcc echoServer.c -o server
gcc echoClient.c -o client
server


...and in second terminal...



client hello
Error in: echoClient.c on line: 58:: No such file or directory









share|improve this question







New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Scott, RalfFriedl, Thomas, Kusalananda, Jeff Schaller Nov 27 at 10:44


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • when the parameters to main() are not going to be used, then use the signature: int main( void )
    – user3629249
    Nov 27 at 7:23










  • this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
    – user3629249
    Nov 27 at 7:32













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a problem with connecting client to server in this code. It worked, but I made some changes and I can't connect to server anymore.



echoServer.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include <ctype.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ;

int server_sockfd = -1 ;
int client_sockfd = -1 ;

void cleanup( void ){
if( server_sockfd != -1 ){
close( server_sockfd ) ;
server_sockfd = -1 ;
}
if( client_sockfd != -1 ){
close( client_sockfd ) ;
client_sockfd = -1 ;
}
}

//converts string to upper case
int strToUpper( char *str , int size ){
int i = 0 ;

while( *str != '' && i++ < size ){
*str = toupper( *str ) ;
str++ ;
}
return i ;
}

int main( int argc, const char *argv ){

int len ;
int client_len ;

//local sockets
struct sockaddr_un server_address ;
struct sockaddr_un client_address ;

atexit( cleanup ) ;

//remove old sockets with same name as specified
unlink(SERVER_ADDRESS);

//create socket
_runSafe(server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0));

//bind a name to socket
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, SERVER_ADDRESS);

_runSafe(bind(server_sockfd, (struct sockaddr *) &server_address , sizeof(server_address)));

//start listening on the named socket
_runSafe(listen(server_sockfd, 10));

while( 1 ) {
memset(Buff, 0, sizeof(Buff));
printf("Server waiting.n") ;

//accept incomming client connection
_runSafe(client_sockfd = accept(server_sockfd, (struct sockaddr*) &client_address, &client_len));

//read message from client
_runSafe(read(client_sockfd, Buff, MAX_MSG_SIZE));
//convert client's message to upper case and reply to client
strToUpper(Buff, sizeof(Buff));
_runSafe(write(client_sockfd, Buff, strlen(Buff)));

//close temporary socket
close( client_sockfd ) ;
client_sockfd = -1 ;

memset(Buff, 0, sizeof(Buff));
}

//program will never reach this point
return 0 ;
}


echoClient.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ; // output message buffer
char Fubb[ MAX_MSG_SIZE ] ; // input message buffer

int Sock_fd = -1 ;

void cleanup( void ){
if( Sock_fd != -1 ){
close( Sock_fd ) ;
Sock_fd = -1 ;
}
}

//client code
int main( int argc, const char *argv ){

int len ;
struct sockaddr_un address ; //this is for local sockets
int result ;

strcpy(Buff, argv[1]);

atexit( cleanup ) ;

//create unnamed socket
_runSafe(Sock_fd = socket(AF_UNIX, SOCK_STREAM, 0));

//set server socket name
address.sun_family = AF_UNIX;
strcpy(address.sun_path, SERVER_ADDRESS);

//connect to server
_runSafe(connect(Sock_fd, (struct sockaddr *) &address, sizeof(address)));
printf("client sending message:%sn", Buff ) ;

//write to socket
_runSafe(write(Sock_fd, Buff, strlen(Buff)));

//read answer from socket
_runSafe(read(Sock_fd, Fubb, MAX_MSG_SIZE));

//show server reply to user
printf("client received reply from server:%sn", Fubb ) ;

//close connection
close( Sock_fd ) ;
Sock_fd = -1 ;

return 0 ;
}


Some settings



    #ifndef _SETTINGS
#define _SETTINGS 1

//some common settings for client and server programs

#define MAX_MSG_SIZE 255 //
#define SERVER_ADDRESS "server_socket" // filename for local sockets

//use the folowing macro for error checking

static char _errBuf[ 1024 ] ;

#define _runSafe( code ) if((code) == -1){
sprintf( _errBuf, "Error in: %s on line: %d:", __FILE__, __LINE__ ) ;
perror( _errBuf ) ;
exit( 1 ) ;
}

#endif


Compiled



gcc echoServer.c -o server
gcc echoClient.c -o client
server


...and in second terminal...



client hello
Error in: echoClient.c on line: 58:: No such file or directory









share|improve this question







New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a problem with connecting client to server in this code. It worked, but I made some changes and I can't connect to server anymore.



echoServer.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include <ctype.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ;

int server_sockfd = -1 ;
int client_sockfd = -1 ;

void cleanup( void ){
if( server_sockfd != -1 ){
close( server_sockfd ) ;
server_sockfd = -1 ;
}
if( client_sockfd != -1 ){
close( client_sockfd ) ;
client_sockfd = -1 ;
}
}

//converts string to upper case
int strToUpper( char *str , int size ){
int i = 0 ;

while( *str != '' && i++ < size ){
*str = toupper( *str ) ;
str++ ;
}
return i ;
}

int main( int argc, const char *argv ){

int len ;
int client_len ;

//local sockets
struct sockaddr_un server_address ;
struct sockaddr_un client_address ;

atexit( cleanup ) ;

//remove old sockets with same name as specified
unlink(SERVER_ADDRESS);

//create socket
_runSafe(server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0));

//bind a name to socket
server_address.sun_family = AF_UNIX;
strcpy(server_address.sun_path, SERVER_ADDRESS);

_runSafe(bind(server_sockfd, (struct sockaddr *) &server_address , sizeof(server_address)));

//start listening on the named socket
_runSafe(listen(server_sockfd, 10));

while( 1 ) {
memset(Buff, 0, sizeof(Buff));
printf("Server waiting.n") ;

//accept incomming client connection
_runSafe(client_sockfd = accept(server_sockfd, (struct sockaddr*) &client_address, &client_len));

//read message from client
_runSafe(read(client_sockfd, Buff, MAX_MSG_SIZE));
//convert client's message to upper case and reply to client
strToUpper(Buff, sizeof(Buff));
_runSafe(write(client_sockfd, Buff, strlen(Buff)));

//close temporary socket
close( client_sockfd ) ;
client_sockfd = -1 ;

memset(Buff, 0, sizeof(Buff));
}

//program will never reach this point
return 0 ;
}


echoClient.c



#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/un.h>
#include <unistd.h>
#include "settings.h"

char Buff[ MAX_MSG_SIZE ] ; // output message buffer
char Fubb[ MAX_MSG_SIZE ] ; // input message buffer

int Sock_fd = -1 ;

void cleanup( void ){
if( Sock_fd != -1 ){
close( Sock_fd ) ;
Sock_fd = -1 ;
}
}

//client code
int main( int argc, const char *argv ){

int len ;
struct sockaddr_un address ; //this is for local sockets
int result ;

strcpy(Buff, argv[1]);

atexit( cleanup ) ;

//create unnamed socket
_runSafe(Sock_fd = socket(AF_UNIX, SOCK_STREAM, 0));

//set server socket name
address.sun_family = AF_UNIX;
strcpy(address.sun_path, SERVER_ADDRESS);

//connect to server
_runSafe(connect(Sock_fd, (struct sockaddr *) &address, sizeof(address)));
printf("client sending message:%sn", Buff ) ;

//write to socket
_runSafe(write(Sock_fd, Buff, strlen(Buff)));

//read answer from socket
_runSafe(read(Sock_fd, Fubb, MAX_MSG_SIZE));

//show server reply to user
printf("client received reply from server:%sn", Fubb ) ;

//close connection
close( Sock_fd ) ;
Sock_fd = -1 ;

return 0 ;
}


Some settings



    #ifndef _SETTINGS
#define _SETTINGS 1

//some common settings for client and server programs

#define MAX_MSG_SIZE 255 //
#define SERVER_ADDRESS "server_socket" // filename for local sockets

//use the folowing macro for error checking

static char _errBuf[ 1024 ] ;

#define _runSafe( code ) if((code) == -1){
sprintf( _errBuf, "Error in: %s on line: %d:", __FILE__, __LINE__ ) ;
perror( _errBuf ) ;
exit( 1 ) ;
}

#endif


Compiled



gcc echoServer.c -o server
gcc echoClient.c -o client
server


...and in second terminal...



client hello
Error in: echoClient.c on line: 58:: No such file or directory






linux c posix unix-sockets






share|improve this question







New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 27 at 5:18









Tomask

1




1




New contributor




Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Tomask is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as unclear what you're asking by Scott, RalfFriedl, Thomas, Kusalananda, Jeff Schaller Nov 27 at 10:44


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Scott, RalfFriedl, Thomas, Kusalananda, Jeff Schaller Nov 27 at 10:44


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • when the parameters to main() are not going to be used, then use the signature: int main( void )
    – user3629249
    Nov 27 at 7:23










  • this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
    – user3629249
    Nov 27 at 7:32


















  • when the parameters to main() are not going to be used, then use the signature: int main( void )
    – user3629249
    Nov 27 at 7:23










  • this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
    – user3629249
    Nov 27 at 7:32
















when the parameters to main() are not going to be used, then use the signature: int main( void )
– user3629249
Nov 27 at 7:23




when the parameters to main() are not going to be used, then use the signature: int main( void )
– user3629249
Nov 27 at 7:23












this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
– user3629249
Nov 27 at 7:32




this is the syntax for accept() int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);. note that the final parameter is an unsigned value, not and int
– user3629249
Nov 27 at 7:32















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt