Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
As title.

C#
private void StartServerToListen()
{
    try
    {
        ServerPort = 1001;
        IPEndPoint ServerIPEndPoint = new IPEndPoint(IPAddress.Any, ServerPort);
        ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        ServerSocket.Bind(ServerIPEndPoint);
        ServerSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.AcceptConnection, true);
        //ServerSocket.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.
        ServerSocket.Listen(32767);
        ServerSocket.BeginAccept(new AsyncCallback(ServerBeginAccept), ServerSocket);
    }
    catch (SocketException se)
    {
        LogAccess.WriteSocketException(ref se, DateTime.Now);
    }
    catch (Exception ex)
    {
        LogAccess.WriteException(ref ex);
    }
}


This is the subroutine that how I start to listen socket from Ethernet. It works well inside the Ethernet (with wire ) but I can't accept any socket connection from wireless device. Please teach me what should I change to accept socket connection from wireless device. And, I ensure that the server side and client side are connected to same AP, in the same subnet mask, IPs are 192.168.x.*
Posted
Updated 26-May-15 15:15pm
v2

1 solution

It should not matter whether the device is wired or wireless as long as they are connected to the same subnet (same IP address range and netmask) and they are running/listening on the same port number.

If the device is not configured/connected to same subnet you would need broadcasting or multi-casting via UDP to find and communicate.
 
Share this answer
 
Comments
Florian Braun 15-May-15 1:28am    
If the devices are not in the same subnet the broadcast via UDP might fail as the broadcast usualy isn't routed from one subnet to the other.

But I have no idea why a connection via wireless network should fail except the router is blocking the pakets
BacchusBeale 16-May-15 16:45pm    
Your need to check the router port forwarding settings. Add the port numbers for you app.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900