Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ServerSocket.accept() problem  RSS feed

 
Jim Hamrick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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?
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!