• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

one client to multiple servers

Hi all,
 My code works for one client to one server :)
I am testing the case one client to 2 servers. It doesn't work. It only transfer files from src to dest1; but dest2 is empty  ( i use src, dest1,dest2 as argument parameter while testing)

Please advise.
client.c
client.h
server.c
server.h
config
0
BeginToLearn
Asked:
BeginToLearn
  • 16
  • 6
  • 6
2 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Begin,

I didn't see this mentioned in an earlier thread, but just to be sure, it's a little unusual to have a client simultaneously connect to multiple servers.  There is absolutely nothing to prohibit it, but generally a client will have a single connection at any point in time while a server will have any number of connections.

Just a thought....

What are you seeing or not seeing?
0
 
BeginToLearnAuthor Commented:
I am implemeting connect to server1 , done then connect to server2. im thinking about it now.please give all aspect advise.tks.just got to work n be home at midnight
0
 
BeginToLearnAuthor Commented:
in addition I dont have experience in design
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Kent OlsenData Warehouse Architect / DBACommented:

That's fine.  It sounds like you have a very good reason for needing to connect to multiple servers from a single client.  FTP clients often work this way so it's definitely a rational thing to do.

0
 
BeginToLearnAuthor Commented:
I am thinking for later feature such as restore files from server to client hihi. I  really want  a flexible n good design so I can rework details easily without rework on all functions
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Let's start with the basics.  :)  If both server programs are running the same object code, the problem should lie either with the configuration of the servers or the client code.

--  Have you changed the connection order?  If you always test by connecting to server1 then server2, you don't know if server2 is set up correctly.  Try connecting to server2 then server1.

--  In run(), do you get an indication that the client program is actually trying to connect to the second server?

-- At lines 360 and 361 you execute the push_back method on both the servername and portno objects.  I suggest that you print both of their values.

-- Print statements in several places in the run() method should isolate this.  
--   What is being returned by gethostbyname()?  
--   Are you sure that you're setting the correct port number?  Check the port number that you've set into serv_addr.sin_port


Kent
0
 
BeginToLearnAuthor Commented:
I will try tonite.at walmart npw.no computer jihi
0
 
BeginToLearnAuthor Commented:
let me check those suggestions. just got home
0
 
BeginToLearnAuthor Commented:
I think should create the vector for :
   + sockfd
   + struct sockaddr_in
   + struct hostent

so i can access to relevant element respectively to each server.Otherwise, it cause problem.  Am i right?

I also need to move sendFilePreparation() outside the loop to avoid redundency
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Begin,

You can, and if you want to maintain simultaneous connections you'll probably want them.

But right now you're using the connections serially.  Only one connection at a time.  It's perfectly fine to reuse these variables.  (Once the program starts working as you want, there are quite a few things that should be cleaned up.  Since they aren't interfering with what you're doing now let's just skip them.)


Kent
0
 
BeginToLearnAuthor Commented:
let me check
--  What is being returned by gethostbyname()?  
--   Are you sure that you're setting the correct port number?  Check the port number that you've set into serv_addr.sin_por

Last night i checked other suggestion and they were right.
0
 
BeginToLearnAuthor Commented:
the gethostbyname() return right ip which is 127.0.0.1
However,serv_addr.sin_port return 14535 for each server. port numbers are supposed to be 51000 and 52000

I have no idea because the push_back got right port numbers which are 51000 and 52000
0
 
BeginToLearnAuthor Commented:
ic a little bit more now.
0
 
BeginToLearnAuthor Commented:
i figured out why :) tks.
I want to ask about the design now for future features. Basically, i have finished backup feature. Now I want to work on restore feature. for example, restore from server1 ( as daemon)  to client.

Could you tell me on how to design ? hihi
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Begin,

That process will look almost exactly like what you've got, except that the files will be transferred the other way.

The code will be pretty easy to follow if you reorganize a bit.  In general, your client and server code have these critical components.

- Client
--  Function send_all_files
--  Function send_file

- Server
--  Function receive_one_file
--  Function receive_total_files

There are other support functions, but these are the basic file exchange methods.  The send logic and receive logic will need to be in both the client and the server functions.  You'll also means that a more robust handshake when restoring files.

In general, the client program will make a request of the server and act upon the answer.  So if you want to restore a directory from the server, you need to send a function to the server that you're going to execute the restore function.  The server will need to process the entire tree just as the client program does now.  The send/receive of the file can work like it does now (with the client and server swapping duties for the restore) or you can let the client drive the entire communications.  Your choice.  It's probably easier to just swap the send/receive duties.


Kent
0
 
BeginToLearnAuthor Commented:
I choice " It's probably easier to just swap the send/receive duties."

Somehow, i keep thinking the Client/Server will have the same components:

- Client
--  Function send_all_files_from_Client
--  Function send_file_from_Client
--  Function receive_all_files_at_Client
--  Functin receive_file_at_Client

- Server
--  Function receive_one_file_at_Server
--  Function receive_total_files_at_Server
--  Function send_one_file_from_Server
 --Function send_all_file_from Server

then all depends on how to use. For example backup,
   Client will use: send all files, send file
   Server will use: receive all files, receive file

for restore, Client will use: receive all files, receive file
                Server will use: send all files, send file

So it means we let both client/server run forever? I get confused on this issue.  
0
 
Kent OlsenData Warehouse Architect / DBACommented:

That's pretty close.  :)

It may not be obvious, but the handshake where the client asks a question and the server answers is just one of many possible protocols.  You could also have the server ask a question and have the client answer.

Translated, once the client and server agree that a file is to be exchanged and which direction the file will move (from client to server or the other way 'round) the exact same code will transfer the file.


Kent



I'm going to be away from my computer for a while.  If any of the other experts can step in, that would be most welcome....

0
 
ssnkumarCommented:
> So it means we let both client/server run forever?
Servers will run for ever.
But, in your case, both server and clients are doing almost same job - either receive files or send files.
So, your client itself, sometimes behaves like a server.
And hence the confusion.

In a typical client-server setup, server will keep running.
Client will connect to server whenever it needs some service.

In your case also, client should connect to the server whenever needed. Hence it need not run always.
0
 
BeginToLearnAuthor Commented:
It seems client and server will have same a lot of  functions . Only difference is the first message will tell them what to do? Am I right?
0
 
ssnkumarCommented:
> Am I right?
In your case, yes.
0
 
BeginToLearnAuthor Commented:
tks a lot. I think i will continue on this after tomorrow. Right now i am working on load balancing techniques and their disadvantages vs advantages (due date tomorrow) . Also i have quiz tomorrow.

I have nothing to contribute here, except for my research :) hihi. Do you want to read it after tomorrow?
0
 
ssnkumarCommented:
All the best.
Let us know, if you have any more questions or doubts.
0
 
BeginToLearnAuthor Commented:
I will close this question tomorrow. When I work on it and ask for help, i will open new questions. .
0
 
ssnkumarCommented:
OK. No issues.
You are always welcome to ask any number of questions.
0
 
BeginToLearnAuthor Commented:
BTW where do you live?
0
 
ssnkumarCommented:
I live in Bangalore, India.
What about you?
0
 
BeginToLearnAuthor Commented:
California. Good night.
0
 
ssnkumarCommented:
Good Night. Bye.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 16
  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now