0

I have a file sharing application with logging capabilities. Every time a user connects, the client sends a string telling that a user is connected, same also when a client disconnects a string, telling that the user was disconnected is sent on the server.

Now my problem is, there is a possibility that when a user connects or disconnect then at the same time is sending a file, the program will not be able to guess which data is for the logging part and which data is for the file sharing part. What I want is to separate them without interrupting each other. The TCP connection is implemented in a single TCP socket, now I'm thinking that, maybe using a separate socket for either of the two functionality can solve the problem. Or maybe some kind of algorithm to determine the type of data sent, whether its a file data or a string. Something that involves the IO library and stuffs like that. My friend told me, that maybe we can try getting the file name of the file being sent and then compare it to the string sent for the logging part. The strings sent for the logging part is constant, so that should be possible, I guess?

I got some ideas running in my head but I think there are better ways to do this. Any suggestions?

Thanks in advance!

Ryklon Zen
  • 173
  • 1
  • 3
  • 19
  • 1
    It's really unclear what the architecture is here. Wouldn't you have a single socket per user, and thus the connection is just the first message in the connection? (You need to work out how to terminate that, of course...) – Jon Skeet Feb 18 '13 at 18:01
  • prefix each chunk of data you sent with an indentifier. e.g. maybe the first byte would be `0x00` = login messge, `0x01` = logout messages, `0x02` = file data, etc... – Marc B Feb 18 '13 at 18:01
  • You could take a lesson from the FTP protocol and use two connections, one for control and a second for file data. That is, if I understand what you are describing correctly. – lc. Feb 18 '13 at 18:02
  • Thank you for your reply. @JonSkeet Yes, a single socket per user. Users can connect and disconnect anytime they want. When they do that, they sent a message informing the server what they did. The logging part is fine that way, but the thing is, sending a file would interrupt the logging part, vice versa. – Ryklon Zen Feb 18 '13 at 18:06
  • @MarcB, that should be great but how can I identify the file data? If a large file is sent, what my program does is send it by parts. The problem lies there, it cannot identify what data is being sent. Its in binary. If I got this wrong, please enlighten me. :) – Ryklon Zen Feb 18 '13 at 18:11
  • it'd be up to your specify a connection/communications protocol. if you're going to be sending multiple different types of data over a single communications channel, you'll have to have some way to identify what you're sending actually is. – Marc B Feb 18 '13 at 18:13
  • @lc. Yes, but I guess a single connection for each user is much better. I'd implement it in separate socket if there's no other choice. – Ryklon Zen Feb 18 '13 at 18:14
  • @MarcB Yeah. So far those mention above are my current ideas. I'm hoping that maybe, there are better ways to this. :) – Ryklon Zen Feb 18 '13 at 18:17
  • @RyklonZen It was just an idea using something already out there. I must be missing something here though. If the user disconnects, wouldn't they be closing the socket mid-transfer? Assuming you have control over the client application, shouldn't the "signoff" message be the last bytes in the stream? – lc. Feb 18 '13 at 18:19
  • @lc. Thanks for that last comment of yours. I get it now, it would not interrupt the transfer of data at all. Nothing gets interrupted because as you've said, the log data will always be at the beginning or at the end of the stream. I guess, I am just over analyzing things. :) – Ryklon Zen Feb 18 '13 at 18:30
  • @RyklonZen I believe so, just do make sure it always happens that way. That is, if you're sending data in a background thread, make sure that terminates *before* you send the "signoff" message and close the connection, otherwise you *will* get junk. – lc. Feb 18 '13 at 18:34
  • @lc. Yes. Thanks for that one. I'll keep it in mind. :) – Ryklon Zen Feb 18 '13 at 18:36

0 Answers0