Click here to Skip to main content
15,895,812 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ win32 console copy files problems Pin
KarstenK13-Apr-09 21:40
mveKarstenK13-Apr-09 21:40 
GeneralRe: C++ win32 console copy files problems Pin
Iain Clarke, Warrior Programmer14-Apr-09 3:52
Iain Clarke, Warrior Programmer14-Apr-09 3:52 
QuestionHelp with a simple phone book program Pin
Subrina Bisnauth13-Apr-09 13:20
Subrina Bisnauth13-Apr-09 13:20 
AnswerRe: Help with a simple phone book program Pin
David Crow13-Apr-09 15:42
David Crow13-Apr-09 15:42 
QuestionC++ Socket/Multithread Programming Question Pin
djcouture13-Apr-09 9:18
djcouture13-Apr-09 9:18 
AnswerRe: C++ Socket/Multithread Programming Question Pin
bulg13-Apr-09 12:05
bulg13-Apr-09 12:05 
GeneralRe: C++ Socket/Multithread Programming Question Pin
djcouture14-Apr-09 3:29
djcouture14-Apr-09 3:29 
GeneralRe: C++ Socket/Multithread Programming Question Pin
bulg14-Apr-09 7:32
bulg14-Apr-09 7:32 
I like your diagram, I'm gonna copy it and add stuff to it


Client 1
Socket 1
|
| Client 2
| |Socket 2
| |
V V
Socket S
^ |
| V
| Server -> Socket R -----> Socket 3 -> Reporting Client
|
|
|
|
Socket X
Client X

Each listening socket must be bound (bind()) to a port number. A process that wants to send information to a listening socket, as far as I know, must use a different socket to send information to the listening socket.

So when you say socket number, I know that sockets are returned from socket() as integers, and I know that listening sockets are bound to port numbers, also integers. Which of those two is a "socket number"?

some code:
// thread 0: TCP Server
...
if(bind(serv_sock, (struct sockaddr*)&serv_addr,sizeof(serv_addr)) < 0){
  //fail()
}

if(listen(serv_sock,MAXPENDING)<0){
  //fail()
}

for(;;) {
  if((client_sock = accept(serv_sock,(struct sockaddr*)client_addr, sizeof(client_addr)) < 0){
    // someone connected
    HandleTCPClient(client_sock)
  }
}
...

//alternate: UDP server
if(bind(serv_sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0){
  // fail()
}

for(;;) {
  if(recv_size = recvfrom(serv_sock, buffer, MAX_BUFFER, 0, (struct sockaddr*)&client_addr, sizeof(client_addr)) < 0) {
    // recv_from failed, try to figure out what happened.
  
  //else, got some data, lets send it to someone else
  sendto(serv_sock, buffer, recv_size, 0, (struct sockaddr*)&other_addr, sizeof(other_addr));
}
I admit that the for(smileyface) may be misleading at first.
GeneralRe: C++ Socket/Multithread Programming Question Pin
djcouture15-Apr-09 5:27
djcouture15-Apr-09 5:27 
QuestionInternet to USB application Pin
2buck5613-Apr-09 9:17
2buck5613-Apr-09 9:17 
AnswerRe: Internet to USB application Pin
bulg13-Apr-09 12:08
bulg13-Apr-09 12:08 
GeneralRe: Internet to USB application Pin
2buck5613-Apr-09 13:04
2buck5613-Apr-09 13:04 
QuestionMore specific question, help please Pin
bulg13-Apr-09 14:32
bulg13-Apr-09 14:32 
AnswerRe: More specific question, help please Pin
2buck5613-Apr-09 15:58
2buck5613-Apr-09 15:58 
AnswerRe: Internet to USB application Pin
Iain Clarke, Warrior Programmer14-Apr-09 4:02
Iain Clarke, Warrior Programmer14-Apr-09 4:02 
GeneralRe: Internet to USB application Pin
2buck5614-Apr-09 5:01
2buck5614-Apr-09 5:01 
QuestionSet Class - Insert Function Pin
aab1990213-Apr-09 7:28
aab1990213-Apr-09 7:28 
AnswerRe: Set Class - Insert Function Pin
David Crow13-Apr-09 7:32
David Crow13-Apr-09 7:32 
QuestionDetect copied file? Pin
steve7606313-Apr-09 6:57
steve7606313-Apr-09 6:57 
AnswerRe: Detect copied file? Pin
David Crow13-Apr-09 7:28
David Crow13-Apr-09 7:28 
GeneralRe: Detect copied file? Pin
steve7606313-Apr-09 8:40
steve7606313-Apr-09 8:40 
GeneralRe: Detect copied file? Pin
Luc 64801113-Apr-09 9:45
Luc 64801113-Apr-09 9:45 
AnswerRe: Detect copied file? [modified] Pin
steve7606313-Apr-09 11:04
steve7606313-Apr-09 11:04 
AnswerRe: Detect copied file? Pin
john563213-Apr-09 19:48
john563213-Apr-09 19:48 
QuestionDeleted File Pin
recmisi13-Apr-09 6:34
recmisi13-Apr-09 6:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.