Multi users in socket access server [on hold] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionWrapping socket connectionspcap and raw socketPath to unix socketSocket remains ESTABLISHED even if remote process is stoppedMulti processing / Multi threading in BASHHow authentication is done between two nodes in tcp/ip or udp client server socketWhat is the difference between lscpu Socket and networking Socket?Multi-threading with for loopSocket Buffer Size and PerformanceRetrieving the SO_INCOMING_CPU of a UDP Socket?
How to override model in magento2?
Using audio cues to encourage good posture
How much time will it take to get my passport back if I am applying for multiple Schengen visa countries?
Why aren't air breathing engines used as small first stages
Why are there no cargo aircraft with "flying wing" design?
Echoing a tail command produces unexpected output?
Why are Kinder Surprise Eggs illegal in the USA?
At the end of Thor: Ragnarok why don't the Asgardians turn and head for the Bifrost as per their original plan?
Compare a given version number in the form major.minor.build.patch and see if one is less than the other
How widely used is the term Treppenwitz? Is it something that most Germans know?
porting install scripts : can rpm replace apt?
English words in a non-english sci-fi novel
How to align text above triangle figure
Why do we bend a book to keep it straight?
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
3 doors, three guards, one stone
What is Arya's weapon design?
Using et al. for a last / senior author rather than for a first author
How do I keep my slimes from escaping their pens?
Okay to merge included columns on otherwise identical indexes?
What is Wonderstone and are there any references to it pre-1982?
What would be the ideal power source for a cybernetic eye?
Identifying polygons that intersect with another layer using QGIS?
Apollo command module space walk?
Multi users in socket access server [on hold]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWrapping socket connectionspcap and raw socketPath to unix socketSocket remains ESTABLISHED even if remote process is stoppedMulti processing / Multi threading in BASHHow authentication is done between two nodes in tcp/ip or udp client server socketWhat is the difference between lscpu Socket and networking Socket?Multi-threading with for loopSocket Buffer Size and PerformanceRetrieving the SO_INCOMING_CPU of a UDP Socket?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i have a code of socket connecting but i have a problem for how can i access with multiple users to the server , i use a loop for() but i use
"i<2 " but me i need to acces to multiple users no just 2 users.
** Code of Server :
#include <netdb.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
// Driver function
int main()
int sockfd, connfd, len,start , end,soport,sokpo;
struct sockaddr_in servaddr,serv_addr;
char ips[2][20];
int portno = 631;
char hostname[30] ;
struct hostent *server;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0)
printf("socket bind failed...n");
exit(0);
else
printf("Socket successfully binded..n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0)
printf("Listen failed...n");
exit(0);
else
printf("Server listening..n");
len = sizeof(servaddr);
// Accept the data packet from client and verification
for(int i=0;i<2;i++)
connfd = accept(sockfd, (SA*)&servaddr,&len );
if (connfd < 0)
printf("server acccept failed...n");
exit(0);
else
printf("server acccept the client...n");
strcpy(ips[i], inet_ntoa(servaddr.sin_addr));
// After Display close the socket
close(sockfd);
** Code of Client:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
int main()
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("192.168.1.5");
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0)
printf("connection with the server failed...n");
exit(0);
else
printf("connected to the server..n");
close(sockfd);
c socket multithreading
New contributor
put on hold as off-topic by Rui F Ribeiro, Kusalananda♦ Apr 12 at 19:56
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
add a comment |
i have a code of socket connecting but i have a problem for how can i access with multiple users to the server , i use a loop for() but i use
"i<2 " but me i need to acces to multiple users no just 2 users.
** Code of Server :
#include <netdb.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
// Driver function
int main()
int sockfd, connfd, len,start , end,soport,sokpo;
struct sockaddr_in servaddr,serv_addr;
char ips[2][20];
int portno = 631;
char hostname[30] ;
struct hostent *server;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0)
printf("socket bind failed...n");
exit(0);
else
printf("Socket successfully binded..n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0)
printf("Listen failed...n");
exit(0);
else
printf("Server listening..n");
len = sizeof(servaddr);
// Accept the data packet from client and verification
for(int i=0;i<2;i++)
connfd = accept(sockfd, (SA*)&servaddr,&len );
if (connfd < 0)
printf("server acccept failed...n");
exit(0);
else
printf("server acccept the client...n");
strcpy(ips[i], inet_ntoa(servaddr.sin_addr));
// After Display close the socket
close(sockfd);
** Code of Client:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
int main()
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("192.168.1.5");
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0)
printf("connection with the server failed...n");
exit(0);
else
printf("connected to the server..n");
close(sockfd);
c socket multithreading
New contributor
put on hold as off-topic by Rui F Ribeiro, Kusalananda♦ Apr 12 at 19:56
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14
add a comment |
i have a code of socket connecting but i have a problem for how can i access with multiple users to the server , i use a loop for() but i use
"i<2 " but me i need to acces to multiple users no just 2 users.
** Code of Server :
#include <netdb.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
// Driver function
int main()
int sockfd, connfd, len,start , end,soport,sokpo;
struct sockaddr_in servaddr,serv_addr;
char ips[2][20];
int portno = 631;
char hostname[30] ;
struct hostent *server;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0)
printf("socket bind failed...n");
exit(0);
else
printf("Socket successfully binded..n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0)
printf("Listen failed...n");
exit(0);
else
printf("Server listening..n");
len = sizeof(servaddr);
// Accept the data packet from client and verification
for(int i=0;i<2;i++)
connfd = accept(sockfd, (SA*)&servaddr,&len );
if (connfd < 0)
printf("server acccept failed...n");
exit(0);
else
printf("server acccept the client...n");
strcpy(ips[i], inet_ntoa(servaddr.sin_addr));
// After Display close the socket
close(sockfd);
** Code of Client:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
int main()
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("192.168.1.5");
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0)
printf("connection with the server failed...n");
exit(0);
else
printf("connected to the server..n");
close(sockfd);
c socket multithreading
New contributor
i have a code of socket connecting but i have a problem for how can i access with multiple users to the server , i use a loop for() but i use
"i<2 " but me i need to acces to multiple users no just 2 users.
** Code of Server :
#include <netdb.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
// Driver function
int main()
int sockfd, connfd, len,start , end,soport,sokpo;
struct sockaddr_in servaddr,serv_addr;
char ips[2][20];
int portno = 631;
char hostname[30] ;
struct hostent *server;
// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0)
printf("socket bind failed...n");
exit(0);
else
printf("Socket successfully binded..n");
// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0)
printf("Listen failed...n");
exit(0);
else
printf("Server listening..n");
len = sizeof(servaddr);
// Accept the data packet from client and verification
for(int i=0;i<2;i++)
connfd = accept(sockfd, (SA*)&servaddr,&len );
if (connfd < 0)
printf("server acccept failed...n");
exit(0);
else
printf("server acccept the client...n");
strcpy(ips[i], inet_ntoa(servaddr.sin_addr));
// After Display close the socket
close(sockfd);
** Code of Client:
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define MAX 80
#define PORT 8080
#define SA struct sockaddr
int main()
int sockfd, connfd;
struct sockaddr_in servaddr, cli;
// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
printf("socket creation failed...n");
exit(0);
else
printf("Socket successfully created..n");
bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("192.168.1.5");
servaddr.sin_port = htons(PORT);
// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0)
printf("connection with the server failed...n");
exit(0);
else
printf("connected to the server..n");
close(sockfd);
c socket multithreading
c socket multithreading
New contributor
New contributor
edited Apr 12 at 19:39
Rui F Ribeiro
42.1k1484142
42.1k1484142
New contributor
asked Apr 12 at 19:32
RoberRober
1
1
New contributor
New contributor
put on hold as off-topic by Rui F Ribeiro, Kusalananda♦ Apr 12 at 19:56
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
put on hold as off-topic by Rui F Ribeiro, Kusalananda♦ Apr 12 at 19:56
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14
add a comment |
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
I put your question on hold. We've had discussions on our Meta site regarding C programming questions, and what I gather from these is that even though a question may be about the standard Unix C API, pure C programming questions are off-topic here. If you can reword your question to not be a C debugging question and instead possibly ask about the core issue, multi-user access to sockets, then I believe the question would be possible to reopen (by a moderator or through the review queue).
– Kusalananda♦
Apr 12 at 20:14