|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
tranfer files using socket in a chat application
Hello,
I have created a simple multithreaded chat application using Java sockets. When a new client connects a new server thread is created to handle communication with that client. I also want to allow clients to transfer files from one computer to another. I think there cannot be direct connection between two clients when using applets. So server has to receive the file from one client and send it to other client. 1. But even then how connection between two clients can be opened. Problem is using socket.getOutputStream() and socket.getInputStream() only one output/input stream is created, so file contents cannot be transferred using that input/output stream because that stream is used to receive and send chat messages and I want clients to continue sending and receiving messages when file is being transferred. 2. Can a server connect to client's computer to some other port (for sending file) if that client is already connected to the server for sending and receiving messages i.e if there is already a socket connection between client and server. 3. Can file be transferred by getting second input/output stream using socket.getInputStream() and socket.getOutputStream() again? |
|
#2
|
|||
|
|||
|
Would it not be possible if you were to create another socket object? Rather than using socket.getOutputStream() / getInputStream(), create another object (ie: socketFiles) and try using the getInputStream() and getOutputStream() with the newly created object.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
"create another object (ie: socketFiles) and try using the getInputStream() and getOutputStream() with the newly created object."
So according to you if a client wants to send a file to other person then it should open another socket on same server port. Accroding to this: 1. how server knows it is not a new chat client but a request to transfer file from one already connected user to another alredy connected user. Because when accepting socket connection server cannot determine if it is new connection from already connected user. Or I have to modify my application completely to send a specific message after client connects that this socket connection is for sending file. 2. Even if I somehow determine that an already connected client (sender of file) wants to send a file to other client then how does server opens another socket connection to another client computer(receiver of file). In this way client also has to act as a server and listen to a specific port and allow server to connect to it. I think it is not very efficient. What do you think? |
|
#4
|
|||
|
|||
|
Quote:
I'm gonna double-check my reference book on this... It's been a while for me... But if I'm not mistaken, you would have to use another specific port for file transfers... Essentially, what you're doing is building a server/client for both systems... So it's a P2P application. Each user acts as a server and a client... Have you had any progress? |
|
#5
|
|||
|
|||
|
Thank you.
I was thinking the way where client has to act as a client and server too. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > tranfer files using socket in a chat application |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|