0
votes

I want to connect my server. My server is listening on port 50000.

            NetworkStream socketStream = null;
            Socket AcceptedClient;// stream for receiving data           
            byte[] bCode;

            TcpListener listener = null;       
            IPAddress local = IPAddress.Any;
            listener = new TcpListener(local, 50000);

In client computer:

I don't know IP and host name of it.

Our IP is in 192.168.1.x

I must have IP or host name of it.

Is it possible that I create socket connection on this scenario?

My question is: Is it possible to connect other computer without IP address?(TCP or UDP) Thank you.

2
It's a bit unclear what you're asking. Are you asking which IP you should listen on? Or do you want to connect to another machine?CodeCaster
You can try to connect to each existing ip address in the 192.168.1.x range.wimh
Bind to 0.0.0.0:50000 but you need to know whether TCP or UDP ( cannot be both).Lex Li
Do you mean that you don't know the ip address of the server ? Or of the client. In case it is the client, you don't need it. But you do need the ip address of the server.Philip Stuyck
If you are behind your own private router, you can give a fixed ip address to your server that is excluded from the dhcp range, or configure it by making use of the mac address to always assign the same ip address. Depends on your kind of router.Philip Stuyck

2 Answers

2
votes

Create UDP Listener object

UdpClient client = new UdpClient();

Define End point for send Code in broadcast mode

IPEndPoint end = new IPEndPoint(IPAddress.Parse("192.168.0.255"),50001);
byte[] bCodeMelli = System.Text.Encoding.Unicode.GetBytes(strCodeMelli);
client.SendAsync(bCodeMelli, bCodeMelli.Length, end);
byte[] bInfo = client.Receive(ref end);
2
votes

If the client doesn't know the address of the server, but is on the same subnet, then consider using a UDP broadcast from the client (that the server will listen for). Have a look at this question: Sending UDP broadcast, receiving multiple messages