Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs283
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joey Le
Cs283
Commits
bd88c3f1
Commit
bd88c3f1
authored
3 months ago
by
Joey Le
Browse files
Options
Downloads
Patches
Plain Diff
Added debugg statements into process CLI REQUESSS
parent
0cfd3639
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment-06/starter/rsh_server.c
+16
-6
16 additions, 6 deletions
Assignment-06/starter/rsh_server.c
with
16 additions
and
6 deletions
Assignment-06/starter/rsh_server.c
+
16
−
6
View file @
bd88c3f1
...
...
@@ -213,50 +213,60 @@ int boot_server(char *ifaces, int port){
ssize_t
bytes_received
;
int
rc
=
OK
;
printf
(
"SERVER: Waiting for client connections...
\n
"
);
while
(
1
)
{
// Accept a client connection
cli_socket
=
accept
(
svr_socket
,
NULL
,
NULL
);
if
(
cli_socket
==
-
1
)
{
perror
(
"
accept
"
);
perror
(
"
SERVER: accept failed
"
);
rc
=
ERR_RDSH_COMMUNICATION
;
break
;
}
printf
(
"SERVER: Client connected. Socket: %d
\n
"
,
cli_socket
);
// Receive data from the client
bytes_received
=
recv
(
cli_socket
,
buffer
,
sizeof
(
buffer
),
0
);
if
(
bytes_received
<
0
)
{
perror
(
"
recv
"
);
perror
(
"
SERVER: recv failed
"
);
close
(
cli_socket
);
rc
=
ERR_RDSH_COMMUNICATION
;
break
;
}
else
if
(
bytes_received
==
0
)
{
// Client disconnected
printf
(
"SERVER: Client disconnected.
\n
"
);
close
(
cli_socket
);
continue
;
}
// Null-terminate the received data
buffer
[
bytes_received
]
=
'\0'
;
printf
(
"SERVER: Received command: %s
\n
"
,
buffer
);
// Check for special commands
if
(
strncmp
(
buffer
,
"stop-server"
,
strlen
(
"stop-server"
))
==
0
)
{
printf
(
"Client requested server to stop
\n
"
);
printf
(
"
SERVER:
Client requested server to stop
.
\n
"
);
rc
=
OK_EXIT
;
close
(
cli_socket
);
break
;
}
// Handle client requests
printf
(
"SERVER: Executing client request...
\n
"
);
rc
=
exec_client_requests
(
cli_socket
);
if
(
rc
<
0
)
{
fprintf
(
stderr
,
"Error processing client requests: %d
\n
"
,
rc
);
fprintf
(
stderr
,
"
SERVER:
Error processing client requests: %d
\n
"
,
rc
);
close
(
cli_socket
);
break
;
}
// Close the client socket
close
(
cli_socket
);
printf
(
"Client socket closed properly
\n
"
);
printf
(
"
SERVER:
Client socket closed properly
.
\n
"
);
}
// Clean up and stop the server
printf
(
"SERVER: Stopping server...
\n
"
);
stop_server
(
svr_socket
);
return
rc
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment