It is required to create the simplest client-server application. I use java.net library. How is it possible to bind server and client sockets to specific ip-addresses?
- What is it like? What does it mean to bind sockets to addresses? - Anton Shchyrov
- That in the message there were those ip-addresses, which I will indicate. - Vaycheslav
- If the client clings to the address 1.1.1.1, then what is the point to indicate in the message the address 2.2.2.2? - Anton Shchyrov pm
- If the client has several addresses, and it is necessary to send not from the default one. - Vaycheslav
|
1 answer
Client socket
String serverIp = "10.0.0.1"; int serverPort = 1234; int clientPort = 1234; InetAddress clientIp = InetAddress.getByName("192.168.1.100"); Socket socket = new Socket(serverIp, serverPort, clientIp, clientPort); Server socket
Socket socket = new Socket(); socket.bind(new InetSocketAddress("10.0.0.1", 1234)); - Thank you. In this case, when creating a client, it is necessary that a server be created. I found out that using DatagramSocket you can send UDP packets (DatagramPacket) without first establishing a connection. - Vaycheslav
|