• 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

ServerSocket.accept() problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How come, when I use ServerSocket.accept(), it stalls lines of code that should already be running? Here's my code:
c2 = Container, jf2 = JFrame, t = timer, ssock = ServerSocket, sock = Socket.

The code gets run through, and doesnt get past sock = ssock.accept(). The weird thing is that the JFrame pops up ( .show() ), but the defaultCloseOperation() isnt set, and the timer isnt .start()'ed. t.isRunning() returns true, but the timer isnt triggering its actionEvents. i know the code is right because as soon as i comment out sock = ssock.accept(), everything works. What is .accept() doing that i dont understand?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ServerSocket.accept() blocks until a client requests a connection. You are probably running this code in the Swing event thread, invoking this method from an event handler or something of that nature, and paralizing any further events from the GUI. Try setting up your server socket in the main() method. It runs in a seperate thread.
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic