I am following up from my last question, where I was suggested to use sockets for a real time chat application using MySQL database. I have been researching some information about the usage of sockets in flutter, after trying several times and several different codes and failing, I clicked inside another stackoverflow question about sockets and found out this code snippet:
import 'dart:io';
import 'dart:async';
Socket socket;
void main() {
Socket.connect("localhost", 4567).then((Socket sock) {
socket = sock;
socket.listen(dataHandler,
onError: errorHandler,
onDone: doneHandler,
cancelOnError: false);
}).catchError((AsyncError e) {
print("Unable to connect: $e");
});
//Connect standard in to the socket
stdin.listen((data) => socket.write(new String.fromCharCodes(data).trim() + '\n'));
}
void dataHandler(data){
print(new String.fromCharCodes(data).trim());
}
void errorHandler(error, StackTrace trace){
print(error);
}
void doneHandler(){
socket.destroy();
}
I may be wrong but I think this may be the way to connect to my database, if it is not please help me out, I would appreciate it. But I can't find a way to write in the database name, username and password in order to access the data from a specific MySQL database.