WebSocket connection to SeismicPortal

SeismicPortal provides (near) realtime information about current earthquakes. They offer a web socket interface at ws://www.seismicportal.eu/standing_order/websocket. It should send a JSON message every time an earthquake is registered (about each 5-15 minutes). I am trying to connect to this websocket and receive such JSON with this code:

import websockets.*;

WebsocketClient wsc;

void setup(){
  wsc= new WebsocketClient(this, "ws://www.seismicportal.eu/standing_order/websocket");

void webSocketEvent(String msg){

I'd expect this to print the JSON as string in the Processing console output, but all I get in there is just that this: [Animation Thread] INFO org.eclipse.jetty.util.log - Logging initialized @752ms.

I think it means that it has connected to the socket successfully. But I never get any messages from it. You can see such socket messages slowly populating the example output on their web page under Last Messages.

This is my first try to do anything with web sockets or Processing, so please give me some basic guidance of how I should do this


  • edited January 2018

    After I run the code above, I let it sit there for a bit and I got the following message :

    "geometry": {
    "type": "Point",
    "coordinates": [
    "type": "Feature",
    "id": "20180124_0000015",
    "properties": {
    "lastupdate": "2018-01-24T03:03:00.0Z",
    "magtype": "mb",
    "evtype": "ke",
    "lon": -149.78,
    "auth": "NEIC",
    "lat": 55.92,
    "depth": 7.0,
    "unid": "20180124_0000015",
    "mag": 4.2,
    "time": "2018-01-24T01:14:05.9Z",
    "source_id": "643150",
    "source_catalog": "EMSC-RTS",
    "flynn_region": "GULF OF ALASKA"

    Let it sit there for a bit and see if you get a messages.

    FYI, I am also getting the Logging initialized message when you I start the sketch.


  • I was using their portal to see if I could retrieve previous events. For example, what I reported before has an id that ends in 000015. I tried this link:


    Start time: 2018-01-24T01:00:00.000
    End time: 2018-01-24T03:05:00.0000

    Generated URL: http://www.seismicportal.eu/fdsnws/event/1/query?limit=10&start=2018-01-24T01:00:00.000&end=2018-01-24T03:05:00.0000

    From the generated raw data, I couldn't retrieve the id ...00015. I let the program run for about 1 hours and I din't get any event. I restarted it and I got an event. Odd vs. coincidence?

    I modified the sketch to attempt to keep track of received events.


    //REFERENCE: https: //forum.processing.org/two/discussion/26097/websocket-connection-to-seismicportal#latest
    //REFERENCE: http: //www.seismicportal.eu/fdsn-wsevent.html
    //**Start time:** 2018-01-24T01:00:00.000  
    //**End time:** 2018-01-24T03:05:00.0000  
    //**Generated URL:** http: //www.seismicportal.eu/fdsnws/event/1/query?limit=10&start=2018-01-24T01:00:00.000&end=2018-01-24T03:05:00.0000
    import websockets.*;
    WebsocketClient wsc;
    StringList rxMsgs;
    void settings() {
      size(900, 600);
    void setup() {
      textAlign(CENTER, CENTER);
      wsc= new WebsocketClient(this, "ws://www.seismicportal.eu/standing_order/websocket");
      rxMsgs=new StringList();
    void draw() {
      color cb=color(random(255), random(255), random(255));
      color ct=color(255, 255, 255)-cb;
      ct=(0xff<<24) | ct; 
      int h=0;
      for (String ss : rxMsgs) {
        text(ss, width/2, h=h+30);
    void webSocketEvent(String msg) {
      JSONObject obj=parseJSONObject(msg);
      float[] pos=obj.getJSONObject("data").getJSONObject("geometry").getJSONArray("coordinates").getFloatArray();
      PVector p=new PVector(pos[0], pos[1], pos[2]);
      rxMsgs.append("New message @ "+millis()+" at "+p);
      println("NEW MESSAGE @ "+millis());
  • edited January 2018

    It is strange. I let my original code run for several times for about 5-15 minutes and it did not do anything besides printing the first logging line. Then I let it run for several hours through the night and it still did not catch anything. This morning I ran it again after seeing Kfrajer's report that it indeed does something. And it gave me some JSON output after mere seconds. Then I tried Kfrajer's extended version, and again, nothing for about 10 minutes. I ran in again, and got two messages and then nothing for long minutes. I can't explain it. Maybe I was just unlucky. But a whole night without earthquakes seems unlikely.

    Anyway, thanks a lot for improving it and showing me some basic JSON handling. Say, is there a time after which this socket ceases to work, some sort of timeout? I saw something about a latch in the source code of the socket library: CountDownLatch latch = new CountDownLatch(1); My intention is to keep the socket alive as long as the process in Processing is running. Also SeismicPortal's python example of the Socket client shows some routine keeping it alive: self.keepalive = stream.io_loop.add_timeout(timedelta(seconds=PING_TIMEOUT), self.dokeepalive) Don't we need anything like this in Processing?

    After a while I see the Processing routine miss some earthquake events, when I compare it with SeismicPortal's Last Messages of their Real Time Socket example

  • Answer ✓

    Not familiar with the lib. I was also thinking there must be a timeout. I can track those event in the real time portal and I can see you can get events in a row but then it stops coming (or receiving).


  • Hmm, it looks like timeout. I found some links about what to do: https://stackoverflow.com/questions/9056159/websocket-closing-connection-automatically https://stackoverflow.com/questions/10585355/sending-websocket-ping-pong-frame-from-browser

    I'll try to use this workaround, listen to onclose events, and when the socket closes, immediately reopen it.

Sign In or Register to comment.