Connection to server socket "Invalid argument"
VlasovRoman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 22 21:06:11 PDT 2015
I have some code.
//client.d
import std.stdio;
import std.socket;
import std.conv;
void main() {
Socket client = new TcpSocket(AddressFamily.INET);
auto addr = new InternetAddress("localhost", 2021);
auto addrServer = new InternetAddress("localhost",
2017);
client.bind(addr);
client.blocking(true);
writeln("Connection...");
client.connect(addrServer);
void[] buffer = new void[245];
while(1) {
ulong size = client.receive(buffer);
if(size > 0) {
writeln(cast(string)buffer);
}
}
scope(exit) {
client.shutdown(SocketShutdown.BOTH);
client.close();
}
}
//server.d
import std.stdio;
import std.socket;
import std.process;
import std.conv;
void main(string[] args) {
Socket client;
Socket server = new TcpSocket(AddressFamily.INET);
auto addr = new InternetAddress(args[1],
to!(ushort)(args[2]));
server.bind(addr);
server.listen(1);
server.blocking(true);
while(1){
try {
client = server.accept();
writeln("New Connection");
}
catch{}
writeln("Running sensors...")
auto sensors = executeShell("sensors");
//writeln(sensors.output);
//wait(sensors);
writeln("Sending data..")
client.send(cast(void[])(sensors.output));
}
scope(exit) {
server.shutdown(SocketShutdown.BOTH);
server.close();
}
}
When i use "localhost" address how address of server for client
socket, i getting working connection, but when i use address like
192.168.106.91, i get error:
std.socket.SocketOSException at std/socket.d(2768): Unable to
connect socket: Invalid argument
How i can to solve my problem?
More information about the Digitalmars-d-learn
mailing list