Hi I am an student. I have this assignment due soon and I need to get it done in Visual C. Pretty much my part of it is to create the threads side of it and the sockets. What is the simplest way to create a thread and sockets ?
thankyou
Name:
Anonymous2007-04-24 21:08 ID:WhQTMVQG
Tcl has a nice socket library, but everything else about that language sucks. Copy the socket code.
Name:
Anonymous2007-04-24 21:16 ID:N8cC75Zq
Better start working. I think you are screwed.
Name:
Anonymous2007-04-24 21:26 ID:bb5qRGK9
So there isn't any like way using the libraries already with C to achieve this ?
to anon: yes i am screwed.
Name:
Anonymous2007-04-25 0:09 ID:ru/CjhPS
Yes, you use the socket library.
$ man socket
Name:
Anonymous2007-04-25 0:44 ID:aL0v53R1
Multithreaded server? Listen on a port until you get a connection, which will net you a socket to the client. Manage that socket in a new thread in the server app.
Name:
noob2007-04-25 2:18 ID:JZ0AMetO
Where do i get a c compiler?
Name:
Anonymous2007-04-25 4:40 ID:BNXZArPH
>>7
I think I have one in my trash.. you can get it if you want
int main(void)
{
fd_set master; // master file descriptor list
fd_set read_fds; // temp file descriptor list for select()
struct sockaddr_in myaddr; // server address
struct sockaddr_in remoteaddr; // client address
int fdmax; // maximum file descriptor number
int listener; // listening socket descriptor
int newfd; // newly accept()ed socket descriptor
char buf[256]; // buffer for client data
int nbytes;
int yes=1; // for setsockopt() SO_REUSEADDR, below
socklen_t addrlen;
int i, j;
FD_ZERO(&master); // clear the master and temp sets
FD_ZERO(&read_fds);
// get the listener
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
// lose the pesky "address already in use" error message
if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(int)) == -1) {
perror("setsockopt");
exit(1);
}
// add the listener to the master set
FD_SET(listener, &master);
// keep track of the biggest file descriptor
fdmax = listener; // so far, it's this one
// main loop
for(;;) {
read_fds = master; // copy it
if (select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1) {
perror("select");
exit(1);
}
// run through the existing connections looking for data to read
for(i = 0; i <= fdmax; i++) {
if (FD_ISSET(i, &read_fds)) { // we got one!!
if (i == listener) {
// handle new connections
addrlen = sizeof(remoteaddr);
if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr,
&addrlen)) == -1) {
perror("accept");
} else {
FD_SET(newfd, &master); // add to master set
if (newfd > fdmax) { // keep track of the maximum
fdmax = newfd;
}
printf("selectserver: new connection from %s on "
"socket %d\n", inet_ntoa(remoteaddr.sin_addr), newfd);
}
} else {
// handle data from a client
if ((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) {
// got error or connection closed by client
if (nbytes == 0) {
// connection closed
printf("selectserver: socket %d hung up\n", i);
} else {
perror("recv");
}
close(i); // bye!
FD_CLR(i, &master); // remove from master set
} else {
// we got some data from a client
for(j = 0; j <= fdmax; j++) {
// send to everyone!
if (FD_ISSET(j, &master)) {
// except the listener and ourselves
if (j != listener && j != i) {
if (send(j, buf, nbytes, 0) == -1) {
perror("send");
}
}
}
}
}
} // it's SO UGLY!
}
}
}
return 0;
}
Name:
Anonymous2007-04-25 12:16 ID:GIgKyTqU
>>12 Why you guys tell him he is screwed?
Here's a hint: this board is full of idiots who can't program for shit.
I have 10+ years of experience and have been involved in multiple high-profile projects. I'm just an asshole to students who post their assignments on message boards instead of actually learning it themselves.
CS *should* have a high learning curve. Dumbass programmers who shouldn't have gotten a degree in the first place, but who skated through college by getting all their answers from the internet, waste competent programmers' time and money because we have to fix their broken code after they've made a mess of everything.
Not a solution, although i suspect it would work, it's not using threads and therefore fails the assignment.
Name:
Anonymous2007-04-25 14:57 ID:ZIaF+r7+
Write it in Python, use py2exe, disassemble, port ASM to C
Name:
Anonymous2007-04-25 17:55 ID:GIgKyTqU
>>14
Then why are you on this forum in the first place? This isn't the typical programming message board, and there's plenty of shit that's more annoying than a student hoping for help with an assignment. There is no reason for you to be an asshole instead of ignoring the thread, unless you aren't really a "competent programmer", and you are threatened by other people learning how to program. Faggot.
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy