need assistance multicast udp server find c#
as kind followup i've gotten fortitude operative internal machine, nonetheless accessory network.
i don't know too many sockets basics, bear me. idea fan feeling server internal network, outcome cut/paste/edit code.
this fan code:
ipendpoint ipep = new ipendpoint(ipaddress.parse("127.0.0.1"), 10294);
byte[] information = new byte[1024];
open form1()
{
initializecomponent();
}
private vacant button1_click(object sender, eventargs e)
{
dale fan = new socket(addressfamily.internetwork, sockettype.dgram, protocoltype.udp);
client.setsocketoption(socketoptionlevel.ip, socketoptionname.multicasttimetolive, 10);
twine acquire = "what's your ip?";
information = encoding.ascii.getbytes(welcome);
client.sendto(data, data.length, socketflags.none, ipep);
ipendpoint server = new ipendpoint(ipaddress.any, 0);
endpoint tmpremote = (endpoint)server;
information = new byte[1024];
int recv = client.receivefrom(data, ref tmpremote);
this.ip.text = ((ipendpoint)tmpremote).address.tostring(); //set textbox
this.port.text = encoding.ascii.getstring(data, 0, recv); //set textbox
client.close();
}
this server code:
int recv;
byte[] information = new byte[1024];
ipendpoint ipep = new ipendpoint(ipaddress.any, 10294);
dale newsock = new socket(addressfamily.internetwork,
sockettype.dgram, protocoltype.udp);
newsock.bind(ipep);
newsock.setsocketoption(socketoptionlevel.ip, socketoptionname.addmembership, new multicastoption(ipaddress.any,ipaddress.parse("127.0.0.1")));
while (true)
{
console.writeline("waiting client...");
ipendpoint sender = new ipendpoint(ipaddress.any, 0);
endpoint tmpremote = (endpoint)(sender);
information = new byte[1024];
recv = newsock.receivefrom(data, ref tmpremote);
console.writeline("message viewed {0}:", tmpremote.tostring());
console.writeline(encoding.ascii.getstring(data, 0, recv));
twine acquire = "7010";
information = encoding.ascii.getbytes(welcome);
newsock.sendto(data, data.length, socketflags.none, tmpremote);
}
it works internal accessory (both server client) nonetheless i try another accessory same network i "an existent tie forcibly closed remote host"
i comprehend i need supplement lot try/catch nonetheless i'm only perplexing hoop works first.
Comments
Post a Comment