File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
blog/25-12-03/unix-sockets/ex Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1515 perror ("socket" );
1616 return 1 ;
1717 }
18-
18+
19+ // remove old socket file
20+ unlink ("/tmp/mysock" );
21+
22+
1923 struct sockaddr_un addr ;
2024 memset (& addr ,0 ,sizeof (addr ));
2125 addr .sun_family = AF_UNIX ;
2226 strcpy (addr .sun_path ,"/tmp/mysock" );
23- // remove old socket file
24- unlink ("/tmp/mysock" );
2527
2628 if (bind (sock ,(struct sockaddr * )& addr ,sizeof (addr ))< 0 ){
2729 perror ("bind" );
2830 return 1 ;
29- }
30-
31+ }
3132 listen (sock ,1 );
33+
34+
3235 int conn = accept (sock ,NULL ,NULL );
3336 if (conn < 0 ){
3437 perror ("accept" );
3538 return 1 ;
3639 }
40+
3741 // Send a test message
3842 const char * msg = "Hello from C over Unix socket!" ;
3943 write (conn ,msg ,strlen (msg ));
44+
4045
4146 close (conn );
4247 close (sock );
You can’t perform that action at this time.
0 commit comments