Closed Coxcopi closed 1 year ago
Hey @Coxcopi could you share a snippet of your code and where the exception is raised?
@lugehorsam sure, this is what the code for setting up client and socket looks like:
func setup() -> void:
_client = _connect_to_server()
_socket = _create_socket(_client)
func _connect_to_server() -> NakamaClient:
var client : NakamaClient = Nakama.create_client(
"defaultkey",
"127.0.0.1",
7350,
"http",
3,
NakamaLogger.LOG_LEVEL.INFO
)
client.timeout = CLIENT_REQUEST_TIMEOUT
return client
func _create_socket(client : NakamaClient) -> NakamaSocket:
if (!client):
return null
return Nakama.create_socket_from(client)
And here's when I tried using methods from the socket:
Joining Matchmaker:
func join_matchmaker(query : String = "*", min_count : int = 2, max_count : int = 8) -> void:
var socket : NakamaSocket = NetServerConnection.get_socket()
if (!socket):
return
var ticket_response : NakamaRTAPI.MatchmakerTicket = await socket.add_matchmaker_async(
query,
min_count,
max_count
)
if (ticket_response.is_exception()):
Logger.log_error("NetMatchManager: join_matchmaker() error: %s" % ticket_response)
matchmaker_ticket = ticket_response.ticket
Following friends status:
func follow_friends_status() -> void:
var socket : NakamaSocket = NetServerConnection.get_socket()
if (!socket):
return
var friends_result : Array[NakamaAPI.ApiUser] = await get_friends(FriendshipState.MUTUAL, 20)
var friend_ids : Array[String] = []
for user in friends_result:
if (!user.online):
continue
friend_ids.append(user.id)
var result : NakamaAsyncResult = await socket.follow_users_async(friend_ids, [])
if (result.is_exception()):
Logger.log_error("PresenceManager: follow_friends_status() error: %s" % result.get_exception().message)
Both of these resulted in the error I mentioned, and I can't seem to figure out where the problem is coming from.
Not sure if that information is also relevant but I'm running the latest nakama docker image locally on a Windows 10 machine using Docker Desktop.
The Request cancelled.
cancelled message comes from the client when there's an error sending data on the WebSocket.
Is there any information in the Nakama logs? In particular, do you see the WebSocket connection coming through?
Also, your code doesn't show authenticating before creating the socket. I'm assuming you're doing that and simply not showing it, but double checking just in case. :-)
@dsnopek there actually is an error thrown in Godot (which I unfortunately didn't really notice before, otherwise I would've included it in the original issue of course), which seems to happen in the NakamaSocketAdapter.send()
method:
E 0:00:12:0795 NakamaSocketAdapter.gd:54 @ send(): Condition "ready_state != STATE_OPEN" is true. Returning: FAILED
Looks like something's wrong with the WebSocket, though I'm not sure if it's an issue with the Nakama addon code or if I'm just missing something.
Also you're absolutely right, I left out the authentication code as I don't think it has to do with the problem, and I made sure that the authentication was working as intended.
Full stacktrace:
<C++ Source> modules/websocket/wsl_peer.cpp:703 @ _send()
<Stack Trace> NakamaSocketAdapter.gd:54 @ send()
NakamaSocket.gd:295 @ _send_async()
NakamaSocket.gd:351 @ follow_users_async()
net_account_manager.gd:237 @ follow_friends_status()
net_account_manager.gd:1347839312 @ get_friends()
NakamaClient.gd:1347838512 @ list_friends_async()
NakamaAPI.gd:1347838192 @ list_friends_async()
NakamaHTTPAdapter.gd:1347836752 @ send_async()
NakamaHTTPAdapter.gd:1347841872 @ _send_async()
NakamaHTTPAdapter.gd:1347842832 @ make_request()
It turns out I'm incredibly stupid. I spent hours digging through the addon code trying to find errors when I just now realized that I never actually called _socket.connect()
, which of course has my methods fail simply because the socket obviously can't send anything without a connection.
I apologize for keeping this issue open for so long (and making it in the first place), next time I'll check my own code first 😄
I have the socket setup correctly, but all methods immediately return a
NakamaException
with error message "Request cancelled." that looks like this:NakamaException(StatusCode={-1}, Message='{Request cancelled.}', GrpcStatusCode={-1})
. Any idea what might be going on here? (The server is also running and the client successfully connects to it, the only thing that's not working is the sockets).Using Godot v4.0.2 stable and nakama-godot on the master branch.