Discussion:
[dart-misc] How to connect Dart socket client to unix server which written with java?
Niyazi Toros
2018-09-20 13:42:09 UTC
Permalink
Hi,


With Dart socket client cannot connect to unix server which written with
java.

In java client I also set socket.setSoLinger(true,0); I am guessing this
not available in Dart

and I am thinking that I get error because of this.


Anyone can help me to find why keep I get these errors.








import 'dart:io';
import 'dart:async';

Socket socket;
String _dataToBeSent = “00802020N0307809491508590203000000000000490012001629
01700CD0";
var reply;

// TODO: MAIN
main(List<String> arguments) {
_remoteServerConnect();
}

// TODO: REMOTE SERVER CONNECT
void _remoteServerConnect() async {
Future<Socket> future = Socket.connect(‘remote_ip_address’,
remote_port);
future.then((client) {
print("connected to server!");
client.handleError((data) {
print(data);
});

client.listen(
(data){
reply = new String.fromCharCodes(data);
print(reply);
},
onDone:(){
print("Done");
},
onError:(error){
print(error);
});
client.writeln(_dataToBeSent + "\n");
}).catchError((){
print('Error connecting');
});
}




ERROR:
connected to server!
Done

Unhandled exception:
SocketException: OS Error: Broken pipe, errno = 32, address = 10.2.170.10,
port = 39240

#0 _rootHandleUncaughtError.<anonymous closure>
(dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _runPendingImmediateCallback
(dart:isolate/runtime/libisolate_patch.dart:115:13)
#4 _RawReceivePortImpl._handleMessage
(dart:isolate/runtime/libisolate_patch.dart:172:5)

Process finished with exit code 255
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/9a1beb21-453a-4616-b526-09b907e743b1%40dartlang.org.
Jonathan Rezende
2018-09-20 13:43:53 UTC
Permalink
Hi Niyazi Toros,

To have quick answers, I suggest you creating an StackOverflow question and pasting the link here.

Atenciosamente,

Jonathan Rezende
Hi,
With Dart socket client cannot connect to unix server which written with java.
In java client I also set socket.setSoLinger(true,0); I am guessing this not available in Dart
and I am thinking that I get error because of this.
Anyone can help me to find why keep I get these errors.
import 'dart:io';
import 'dart:async';
Socket socket;
String _dataToBeSent = “00802020N0307809491508590203000000000000490012001629 01700CD0";
var reply;
// TODO: MAIN
main(List<String> arguments) {
_remoteServerConnect();
}
// TODO: REMOTE SERVER CONNECT
void _remoteServerConnect() async {
Future<Socket> future = Socket.connect(‘remote_ip_address’, remote_port);
future.then((client) {
print("connected to server!");
client.handleError((data) {
print(data);
});
client.listen(
(data){
reply = new String.fromCharCodes(data);
print(reply);
},
onDone:(){
print("Done");
},
onError:(error){
print(error);
});
client.writeln(_dataToBeSent + "\n");
}).catchError((){
print('Error connecting');
});
}
connected to server!
Done
SocketException: OS Error: Broken pipe, errno = 32, address = 10.2.170.10, port = 39240
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#4 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)
Process finished with exit code 255
--
For more ways to connect visit https://www.dartlang.org/community <https://www.dartlang.org/community>
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/9a1beb21-453a-4616-b526-09b907e743b1%40dartlang.org <https://groups.google.com/a/dartlang.org/d/msgid/misc/9a1beb21-453a-4616-b526-09b907e743b1%40dartlang.org?utm_medium=email&utm_source=footer>.
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/51E105F0-51B8-4860-BF10-B8FFA8368F72%40jode.com.br.
Niyazi Toros
2018-09-21 08:35:25 UTC
Permalink
@Jonathan, I already post in stack
overflow https://stackoverflow.com/questions/52425195/how-to-use-rawsocket-in-dart?noredirect=1#comment91801891_52425195

I am guessing that the error comes from the connection close, and I don't
know the server connection feature.

*Best I come up with the dart code is this;*
import 'package:untitled/untitled.dart' as untitled;
import 'dart:io';
import 'dart:async';

Socket socket;
String _dataToBeSent = "00802020N030780949";
var reply;

// TODO: MAIN
main(List<String> arguments) async {
await _remoteServerConnect();
}

// TODO: REMOTE SERVER CONNECT
Future _remoteServerConnect() async {

await Socket.connect(‘remote_ip’, remote_port).then((Socket sock) {
socket = sock;
socket.listen(dataHandler,
onError: errorHandler,
onDone: doneHandler,
cancelOnError: false);
}).catchError((AsyncError e) {
print("Unable to connect: $e");
exit(1);
});

print(_dataToBeSent);
await socket.write(_dataToBeSent + '\n');
}

void dataHandler(data) async {
String _result = await String.fromCharCodes(data).trim();
print(_result);
}

void errorHandler(error, StackTrace trace){
print(error);
}

void doneHandler(){
socket.destroy();
exit(0);
}



*And this is the error I get if I run first time:*
I send: 00802020N030780949
I get: 04072Success
The Error: SocketException: OS Error: Connection reset by peer, errno =
104, address = ***.***.***.***, port = 40872

*If I wait 2 or 3 second and run again I don't get result but get this
error:*
I send: 00802020N030780949
The Error: SocketException: OS Error: Connection reset by peer, errno =
104, address = ***.***.***.***, port = 41006
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/35485a84-1658-4031-9c36-71f48d16b888%40dartlang.org.
Loading...