This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Sockets JavaBean Required  RSS feed

 
Michael Erskine
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does anyone have a pair of TCP/IP sockets JavaBeans to act as client and server. I ask because I'm not suitably qualified to create them myself and since this is a pretty common task there just has to be someone who has taken the time to write and test something bulletproof!
BTW: I am aware of JavaBeans API, Magercise 9 - but this doesn't look quite right - I was looking for something using BufferedInputStream or DataInputStream (for platform independence) that perhaps provides keepalives/heartbeats/timeouts.
Regards,
Micahel.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Writing a client/server app over TCP/IP sockets is a fairly trivial matter using Java. You can easily set the the plumbing up using the ServerSocket class for the server and the Socket class for the client. The ServerSocket has an accept() method that blocks until a connection is established with a client (which returns a Socket.) The Socket class has getInputStream() and getOutputStream() methods for communication between client and server. The whole thing can be setup with just a few lines of code for both client and server. It's not much more difficult to add threading for multiple client connections. The only difficult part is implementing your communication protocol which is something you'll have to do whether or not you have a prewritten Bean. If you setup the server first, you can test it with telnet. Just make sure you use a port above 1024 since Unix boxes require superuser access for all ports below that.
Hope this helps,
Michael Morris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!