- Home /
why does the 2 computers connection between the server(python) and the client (C# in unity) does not work?
I am trying to play my unity game from 2 computers (one is the server(python) and one is the client(unity and C#)), but when I try to connect the unity console shows me this error:
"SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."
can you help me figure this out?
this is the client c# code(unity):
socket my_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.43.95"), 7770);
my_socket.Connect(endPoint);
this my serever code(python):
import socket
my_socket = socket.socket()
my_socket.bind(('0.0.0.0', 7770))
my_socket.listen(5)
(client_socket, client_address) = my_socket.accept()
print str(client_address)+" is connected"
Answer by Bunny83 · May 04, 2020 at 09:33 AM
I don't see a particular issue with your code apart from the fact that I never really used python and can't verify if the code you use is working the way you intended. The only thing I can say about your server is that you can only ever connect a single client with the code provided. I'm not sure if pythons accept() method is blocking and if it has a timeout.
Is there a reason why you use a raw socket in C#? If you want a TCP connection it's generally simpler to use a TCPClient. Keep in mind that TCP does not work on packets but on a continous datastream.
However if the connection already fails I would assume some firewall issues on one or both of the PCs.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating an app for mobile and browsers 1 Answer
Adapt OnMouseDown to control with Gamepad? 0 Answers
tags on ContactFilter2D? 0 Answers