%%
Last Updated:
- [[2021-02-09]]
- [[2021-01-26]]
%%
Responses from servers via a web socket are usually received as byte code, so we need to convert byte code into [[Unicode]] to parse it and understand it.
## Getting the hexadecimal representation in Unicode of a character
`ord()`
## Decoding byte code
`decode()`
```python
while True:
data = mysock.recv(512)
if ( len(data) < 1):
break
mystring = data.decode()
print(mystring)
```
## Encoding a string into byte code to send to a server
`encode()`
```javascript
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('nicolevanderhoeven.com', 80))
cmd = 'GET https://nicolevanderhoeven.com'.encode()
mysock.send(cmd)
```