• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Currently receiving data from Serial Port, now data will be received from TCP IP port

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts,

Currently I am using a Java program to read data from a machine that is connected through a Serial Port.
The purpose of this machine is to send data at irregular intervals over serial port.
In Java program I have implemented SerialPortEventListener where I am calling serialEvent(SerialPortEvent event) to read data from machine.
Whenever, machine sends data at irregular intervals, my Java code is able to listen to that event and data is read successfully.

Now client wish to purchase a new machine which will communicate data only over TCP/IP port.
I have already goggled this and have understood how to read data over TCP/IP port using sockets in Java.

However challenge that comes in my mind is reading data from machine at irregular intervals.
Like in serial port this is automatically done using serialEvent function as this function is automatically triggered on incoming data, BUT how is this possible in TCP/IP ?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saurabh Agarwal wrote:I have already goggled this and have understood how to read data over TCP/IP port using sockets in Java.



That's a good start.

However challenge that comes in my mind is reading data from machine at irregular intervals.



That shouldn't be a challenge: you already know how to read data from a socket. Why is it an issue that the data arrives at irregular intervals?

Like in serial port this is automatically done using serialEvent function as this function is automatically triggered on incoming data, BUT how is this possible in TCP/IP ?



It isn't. You don't get an event from the socket when data arrives, so you can't use event-driven code. But all you have to do is to read from the socket.

Perhaps you hadn't realized that the socket will wait for data to arrive? When you read from the socket your code will block until some data has arrived, and then your code will get that data.
 
Saurabh Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou for reply,
Your post is helpful.

For now our client has decided to continue with Serial port communication.
But I will try out a POC for future purposes based on understanding from this forum.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
It isn't. You don't get an event from the socket when data arrives, so you can't use event-driven code. But all you have to do is to read from the socket.

Perhaps you hadn't realized that the socket will wait for data to arrive? When you read from the socket your code will block until some data has arrived, and then your code will get that data.



Additionally, if you have a lot of event driven code (that would be annoying to change), it shouldn't be too difficult for you to write a wrapper layer, that will read from the socket and calls your event code when the data arrives. You will likely need a separate thread though.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic