I have a college project where I need to extend an existing spreadsheet application (CleanSheets – open source).
Right now, it’s just a simple spreadsheet application. What I was asked to implement is a menu option that allows a user to share a sheet (i.e. the user selects ‘share a sheet’ – it’s the current one – and then selects the area that they wish to share: A1:A9, for example). Then they can specify a local port and the share is created.
The other users who wish to connect to that share will have to know the machine’s IP and the port to connect. Once they input that info under a menu option called ‘join a shared sheet’ then that shared area will appear in their current sheet, and they are free to edit and view what others are typing in those cells.
Everyone has read/write access – that must be controlled by threads (because we can have 1 person sharing and 3 peers connected to that sheet, all viewing the changes and making their own). Multiple exclusion will have to be guaranteed (this can be done with Semaphores and/or Reentrantlocks).
The sharing implementation has to implemented in a peer to peer architecture.
Now my question is: how to I start developing with sockets in Java? I’ve read some documentation in Java, especially about JXTA, but that’s most likely not what I need. I don’t need a complex P2P application, just that sharing ability.
I’m assuming I need to use UDP (because TCP is mostly server-client, and anyone can be a server or a client here) and I don’t need packet control. I already know about sockets in C. Which classes should I use in Java related to sockets?
java.io and java.net have some useful classes you might want to look at. This is a pretty simplified example because I’ve ignored catching/throwing but hopefully it’ll sort of show what you can do for tx/rx.
write bytes ought to be able to take in something serializable.
Send data:
hope this helps.