Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:21:25+00:00 2026-06-09T02:21:25+00:00

I wait for clients with ServerSocket.accept() and then process like this: val in =

  • 0

I wait for clients with ServerSocket.accept() and then process like this:

val in = new BufferedReader(new InputStreamReader(socket.getInputStream()))
var line = in.readLine()
while (line != null) {
//...
line = in.readLine()
}

How do I know that the client finished sending the headers, in order to send a response?

Specifically I mean these headers:

GET /mychat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Version: 13
Origin: http://example.com

Like described: http://en.wikipedia.org/wiki/WebSocket

I tried:

if (line.contains("\r\n")) {
    println("1")
}
if (line.contains("\r")) {
    println("2")
}
if (line.contains("\n")) {
    println("3")
}

But it doesn’t work…

Something which worked, was line.isEmpty(). But it’s strange, since the stream should contain something and all the contains return false…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:21:26+00:00Added an answer on June 9, 2026 at 2:21 am

    readLine removes the \r\n from the end of each line it reads, thus an empty line is just "" without any \r or \n characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering about, how I can wait a ServerSocket connection on Socket client
Given this: . . . ServerSocket serverSocket = new ServerSocket(1111); while (helperSockets.size() < Common.NUM_HELPERS)
In Java you can wait on every object, so this kind of scenario is
Will this code ever wait on the mutex inside the producer's void push(data) ?
i've a minimal server which wait until a client connect ,then he start a
I use an ArrayBlockingQueue in my code. Clients will wait until an element becomes
This server can handle 2 types of clients one which request one shot data
I wrote two applictions which comunicate by socket. This is the code: Server: import
Suppose you have a socket listening on a TCP port, and some clients are
in a part of my code i write in socket from server and wait

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.