• Post Reply Bookmark Topic Watch Topic
  • New Topic

Receiving streaming real-time updates on a socket  RSS feed

 
Sameer Amte
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm implementing a socket client that makes two socket connections to a server. The first socket connection is bidirectional i.e., can send data and will continuously receive callbacks and heartbeats. The second socket is unidirectional i.e., will receive real-time updates on this socket. The performance and recovery is very important as it is a 24/7 available system with high vol real time data. I've tried to keep the design simple using the following code.
1) Create a socket connection to the server.
2) Get a BufferedWriter on the OutputStream of the socket. This will be used to write data to the server on this thread.
3) Create a separate thread for receiving real-time updates on this socket.
The run method looks like this :
<code>
public void run() {

try {
inpStream = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inpStream));
String result;
while (continueRunning) {
while ((result = tradeReader.readLine()) != null) {
System.out.println("Data received = " + result);
//WorkQueue.add(resultStr);
}
}
}
catch (IOException ioe) {
System.out.println("IOException in Trade Socket Thread : Message = " + ioe.getMessage());
ioe.printStackTrace();
}
</code>

On any exception I need to implement a close the socket connection and a retry logic. On receiving data on the socket it will be written to a queue which will be polled in a separate dispatcher thread to dispatch events to listeners.

Does the use the socket libraries above sound right? Is there anything more that I need to do in terms of keeping the socket connection up and running and implementing a retry?

Thanks
Sameer
 
Amit A. Patil
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks good , try stress testing.Also remember to close all streams and sockets in finally block...
 
Sameer Amte
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In relation to the above code. I changed it further to send data to the server and the data is not reaching the server. On monitoring the network traffic, I can see that it's displaying a "TCP Checksum Incorrect' on Ethereal. It's a very simple send. I'm just getting the outputstream on the socket and send a byte array using the String.getBytes() method.
Any ideas??

Thanks
Sameer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!