sockets - C# Application Lags when Communicating over TCP -
i making simple communication between client application , server application.
server:
tcplistener tcp = new tcplistener(ipaddress.parse("192.168.1.66"),9000); tcp.start(); textbox.text += "start listening \r\n"; //1 socket s = tcp.acceptsocket(); textbox.text += "client has connected \r\n";
the lagging occurs following way, string number 1 not show until client has connected, application freezes, can't drag window.
i tried adding delay:
textbox.text += "start listening \r\n"; system.threading.thread.sleep(1000); socket s = tcp.acceptsocket(); textbox.text += "client has connected \r\n";
still won't allow first message printed , search sockets. application keeps on freezing until client connected.
are doing listening on thread? if not locking gui updating.
void startlistener() { system.threading.thread listenerthread = new system.threading.thread(listenerthread)); listenerthread.isbackground = true; // causes thread close if app closed listenerthread.start(); } void listenerthread() { tcplistener tcp = new tcplistener(ipaddress.parse("192.168.1.66"),9000); tcp.start(); updatestatus("start listening \r\n"); //1 socket s = tcp.acceptsocket(); updatestatus("client has connected \r\n"); //1 // listen more messages, or close listener here. } void updatestatus(string message) { if(invokerequired) invoke((methodinvoker)delegate { updatestatus(message); }); else textbox.text = message; }
Comments
Post a Comment