c# - make server-client work unlimitedly -
how can make server , client run unlimitedly , able exchange data(meaning, until application closed), instead of run 1 exchange of information only. tried while(true)
maybe didn't put on right place , can't reach methods closing , stopping socket , listener. here's of code of server:
public static void startserver() { try { ipaddress ip = ipaddress.parse("192.168.1.11"); tcplistener mylistener = new tcplistener(ip, 8000); mylistener.start(); socket s = mylistener.acceptsocket(); byte[] b = new byte[100]; int k = s.receive(b); ... other actions ... s.close(); mylistener.stop(); }
and then main()
invoke it. client same story.
you can create infinite loop contains receive function processing data, , returns receive. way server excepts data client until server, or client terminates.
while(true) { byte[] buffer = new byte[100]; s.receive(buffer); //do data... }
beware through because in current design 1 client supported. if want support multiple clients consider using threads.
Comments
Post a Comment