Hi All,
I am trying to create Socket Server using below code
Update:
// Server
void SetupServer()
{
try
{
IPEndPoint ipEndPoint = new IPEndPoint (IPAddress.Parse("192.168.0.2"), 9093);
Socket _serverSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_serverSocket.Bind (ipEndPoint);
_serverSocket.Listen (100);
_serverSocket.BeginAccept (new AsyncCallback (AcceptCallback), null);
}
catch (Exception ex)
{
Debug.Log (ex.Message());
}
}
void AcceptCallback(IAsyncResult ar)
{
Socket clientSocket = _serverSocket.EndAccept(ar);
_serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);
Debug.Log("Client { " + clientSocket.GetHashCode() + " } Connected...");
clientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(RecieveCallback), clientSocket);
}
// Client
void SetupClient()
{
try
{
IPEndPoint remoteEndPoint = new IPEndPoint (IPAddress.Parse("192.168.0.2"), 9093);
Socket _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_clientSocket.BeginConnect(remoteEndPoint, new AsyncCallback(ConnectCallback), _clientSocket);
}
catch (Exception ex)
{
Debug.Log (ex.Message());
}
}
void ConnectCallback(IAsyncResult ar)
{
Socket listener = (Socket)ar.AsyncState;
Socket handler = listener.EndConnect(ar);
Debug.Log("connected to " + listener.RemoteEndPoint.ToString());
}
But when i export the build as stand-alone exe and run it on windows machine, it always connects to 192.168.0.2:80 port.
It should connect to port 9093.
Whats wrong i am doing?
Any help would be appreciated.