I have a server that has been implemented by java and a flutter code and I want to connect this two by sockets in both sides. but the flutter side does not connect to java.how can I do this?
here is my simplified code for flutter side:
import 'dart:io';
import 'dart:async';
void main() async{
Socket socket = await Socket.connect("10.0.2.2",8080);
print('the work has finished');
socket.write("hello");
print('ok');
}
this is the java endpoint implementation:
public class main {
public static void main(String[] args) {
Server server = new Server();
try(Socket socket = server.serverSocket.accept(); DataInputStream dataInputStream = new DataInputStream(socket.getInputStream())){
System.out.println("someone has connected to this device");
String message = dataInputStream.readUTF();
System.out.println(message);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
it is good to mention that the server class in used in java side just listens on a specified port =.
2
Answers
Your answer is unclear. It does definitely need some improvement, to help you.
Hoping that the java websocket works you should treat it as any websocket
please go through
https://docs.flutter.dev/cookbook/networking/web-sockets
and that should really help
i would also add that you can try connecting to demo websockets to see if your flutter implimentation works then now make sure the java one works
have a good time 🙂