Regarding client-server ???

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 297
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Regarding client-server ???

 
0
  #1
Jun 9th, 2008
I am creating client -server architecture ...
1 server and 20 clients..are attached ...
when computer starts client sends abc.txt file information to server ...through socket port no 8000...server take this file and rename with that comp name...

problem is ->
when number of clients machine on at same time ..they sends information to server and server gets mixed output....socket is same.

how to solve this problem so server gets output individually for client??

Do i need to create a separate Server for every Client,or is any other way to archive this ??
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,996
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Regarding client-server ???

 
0
  #2
Jun 9th, 2008
Could you show some code from the server part? Only the connecting bit for example?
Also: what OS are you using?
Last edited by niek_e; Jun 9th, 2008 at 4:25 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 297
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Regarding client-server ???

 
0
  #3
Jun 9th, 2008
  1. #include<conio.h>
  2. #include <stdio.h>
  3. #include "winsock2.h"
  4. #include<iostream>
  5. #include<fstream>
  6. #include <stdlib.h>
  7. #include<string>
  8.  
  9. using namespace std;
  10. int i=1;
  11.  
  12. int main()
  13. {
  14.  
  15. WSADATA wsaData;
  16. SOCKET RecvSocket;
  17. sockaddr_in RecvAddr;
  18. int Port = 8000;
  19. char RecvBuf[26000];
  20. int BufLen = 26000;
  21. ifstream in_file;
  22. ofstream out_file;
  23. in_file.close();
  24. in_file.clear();
  25. out_file.close();
  26. out_file.clear();
  27. size_t counter(0); // how many found
  28. string if_name="xyz.txt";
  29. string of_name="abc.txt";
  30. char my_char;
  31.  
  32. char firstipadd[20] ;
  33. int result,p;
  34. char* ipadd;
  35. string s;
  36. sockaddr_in SenderAddr;
  37. int SenderAddrSize = sizeof(SenderAddr);
  38.  
  39. // Initialize Winsock
  40. WSAStartup(MAKEWORD(2,2), &wsaData);
  41. while(1)
  42. {
  43.  
  44. in_file.close();
  45. in_file.clear();
  46. out_file.close();
  47. out_file.clear(); char fname[30] = "C:\\" ;
  48. //-----------------------------------------------
  49. // Create a receiver socket to receive datagrams
  50. RecvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  51.  
  52. //-----------------------------------------------
  53. // Bind the socket to any address and the specified port.
  54. RecvAddr.sin_family = AF_INET;
  55. RecvAddr.sin_port = htons(Port);
  56. RecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  57.  
  58. bind(RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr));
  59. recvfrom(RecvSocket,RecvBuf,BufLen, 0,(SOCKADDR *)&SenderAddr, &SenderAddrSize);
  60.  
  61. FILE * pFile;
  62. string aa;
  63. pFile = fopen ("c:\\xyz.txt" , "w");
  64. fwrite (RecvBuf , 1 ,sizeof(RecvBuf) , pFile);
  65.  
  66. fclose (pFile);
  67. //-------------------
  68.  
  69. printf("Socket close");
  70.  
  71. closesocket(RecvSocket);
  72.  
  73. }
  74. // Clean up and exit.
  75. printf("Exiting.\n");
  76. WSACleanup();
  77. getch();
  78. }
Last edited by Ancient Dragon; Jun 9th, 2008 at 8:15 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 297
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Regarding client-server ???

 
0
  #4
Jun 9th, 2008
i m using. XP...
server is continuously running ....
i m forget to add renaming of file code...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 982
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 210
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: Regarding client-server ???

 
0
  #5
Jun 9th, 2008
Shouldn't you by now be familiar with code tags??
http://www.daniweb.com/forums/misc-explaincode.html
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 297
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Regarding client-server ???

 
0
  #6
Jun 9th, 2008
  1. #include<conio.h>
  2. #include <stdio.h>
  3. #include "winsock2.h"
  4. #include<iostream>
  5. #include<fstream>
  6. #include <stdlib.h>
  7. #include<string>
  8.  
  9. using namespace std;
  10. int i=1;
  11.  
  12. int main()
  13. {
  14.  
  15. WSADATA wsaData;
  16. SOCKET RecvSocket;
  17. sockaddr_in RecvAddr;
  18. int Port = 8000;
  19. char RecvBuf[26000];
  20. int BufLen = 26000;
  21. ifstream in_file;
  22. ofstream out_file;
  23. in_file.close();
  24. in_file.clear();
  25. out_file.close();
  26. out_file.clear();
  27. size_t counter(0); // how many found
  28. string if_name="xyz.txt";
  29. string of_name="abc.txt";
  30. char my_char;
  31.  
  32. char firstipadd[20] ;
  33. int result,p;
  34. char* ipadd;
  35. string s;
  36. sockaddr_in SenderAddr;
  37. int SenderAddrSize = sizeof(SenderAddr);
  38.  
  39. // Initialize Winsock
  40. WSAStartup(MAKEWORD(2,2), &wsaData);
  41. while(1)
  42. {
  43.  
  44. in_file.close();
  45. in_file.clear();
  46. out_file.close();
  47. out_file.clear(); char fname[30] = "C:\\" ;
  48. //-----------------------------------------------
  49. // Create a receiver socket to receive datagrams
  50. RecvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  51.  
  52. //-----------------------------------------------
  53. // Bind the socket to any address and the specified port.
  54. RecvAddr.sin_family = AF_INET;
  55. RecvAddr.sin_port = htons(Port);
  56. RecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  57.  
  58. bind(RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr));
  59. recvfrom(RecvSocket,RecvBuf,BufLen, 0,(SOCKADDR *)&SenderAddr, &SenderAddrSize);
  60.  
  61. FILE * pFile;
  62. string aa;
  63. pFile = fopen ("c:\\xyz.txt" , "w");
  64. fwrite (RecvBuf , 1 ,sizeof(RecvBuf) , pFile);
  65.  
  66. fclose (pFile);
  67. //-------------------
  68.  
  69. printf("Socket close");
  70.  
  71. closesocket(RecvSocket);
  72.  
  73. }
  74. // Clean up and exit.
  75. printf("Exiting.\n");
  76. WSACleanup();
  77. getch();
  78. }

is Multi-Threaded architecture works for it??
how??
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Regarding client-server ???

 
0
  #7
Jun 9th, 2008
>>how to solve this problem so server gets output individually for client??
Each client needs to use different ports. You can reserve a range of ports in the hosts file on the server computer so that nothing else on the server will take them. Assign port no 8000 to client #1, port 8001 to client #2, etc. Then in server side when recvfrom() gets something from client, server kicks off a thread to process the info so that the server can go back to recvfrom() without blocking.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 845 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC