Need help - Socket Server always connects to port 80

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.

One probability is that your port 9093 is blocked by your firewall hence it connects to port 80 because it is available?

:smiley: HarshadK…@Structed: the code is working at my end too…i was digging at wrong place (in my code for 80 port connection) …the issue was with firewall :slight_smile: …anyway thanks for your help…the q’s is close we can say :smiley:

Programmer life: if you close one prob…next two are waiting for you…now some brainstroming needed to handle multiple concurrent req…