Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write on a port

 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application listening on a port.
How do i approach writing a client which writes a string on a port in java?

I am not sure what to look for, a socket approach needs a server to be listening on the port which accepts the connection from the client.
I want my writing to a port to be asynchronous i.e. It doesnt matter if any application is listening or not, i should just be able to write.

Please advise.
 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it should be a guaranteed write to the port. because using UDP, there is no guarantee that the message was written to the port or lost before that.

Any help would be greatly appreciated.
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the Sockets chapter of the Java Tutorial. In Java, Sockets are an abstraction of TCP/IP and Datagrams are UDP.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fahad siddiqui:

I want my writing to a port to be asynchronous i.e. It doesnt matter if any application is listening or not, i should just be able to write.

I do not think that this is possible without a listening server.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want my writing to a port to be asynchronous i.e. It doesnt matter if any application is listening or not, i should just be able to write.


As noted before, that's not something sockets can do on their own. I've run into that requirement many times and built some kind of "store and forward" solution. For example, if the server is down you might store messages locally until it comes back up, then send them in batch. Or you might use JMS over a messaging product like IBM's WebSphere-MQ with store and forward built into persistent queuing. Of course that still fails if the MQ server is down.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic