M
M
MagistrZoom2015-12-21 15:19:56
linux
MagistrZoom, 2015-12-21 15:19:56

What am I doing wrong in gawk's websocket server implementation?

There is the following problem. gawk has a special file "/inet/tcp/port/remotehost/remoteport" for working with tcp. You can write to it and read from it.
How WebSocket works:
1) The client sends a handshake to the server in the form of an HTTP header
2) The server converts the client's key in a special way and responds with a similar HTTP header
3) After receiving the server's response, the client leaves the tcp connection open. Now they can exchange frames.
Actually, the handshake passes, the server sends messages to the client (and he even receives them), but when I try to read the answer from the file (port), then .. awk does not read it! That is, it hangs on getline.

BEGIN { 
#SETTINGS
  RS = ORS = "\r\n"
  port = 8089
  host = "/inet/tcp/" port "/0/0"  # host string 

#END OF SETTINGS

  receive_handshake(header, host)
  #lets do it
  # 1) Calculate hash
  hash = calculate_hash(header["Sec-WebSocket-Key"]);
  # 2) ????
  # 3) send an answer
  answer_handshake(hash, host)


#	print frame |& host
  frame = dataframe_encode("user")
# проблема начинается здесь:
  answer = ""	
  host |& getline answer
  printf answer
  data = dataframe_decode(frame,unmasked)

  close(host)
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question