sockets - TcpClient.Connect takes too much time in .NET compact framework -


i'm having problem method .connect of class tcpclient.

i have working tcpserver listening on port 9100 @ ip 10.0.0.134.

i'm connecting mysocket.connect("10.0.0.134",9100)

(i tried both mysocket = new system.net.sockets.tcpclient("10.0.0.134",9100) , mysocket = new system.net.sockets || mysocket.connect("10.0.0.134",9100))

but software in row stuck 12-13 seconds. after that, can read exception

"system.net.sockets.socketexception"

that not caught try/catch cant' see error description.

any idea improve velocity of connection?

afterall, connection working , can send data through tcp/ip

i'm developing software on windows ce 6 compact framework 3.5 , visual studio 2008

don't put socket initialization in class constructor unless absolutely must.

if must, hard code socketexception:

private bool abortlistener; private tcplistener listener; private textbox textbox1;  public tcp_class() {   abortlistener = false;   try {     listener = new tcplistener(system.net.ipaddress.any, 8000);   } catch (socketexception err) {     listener = null;     textbox1.text = err.message;   } }  public void listen(string ipstring, int port) {   if ((listener == null) || !string.isnullorempty(ipstring)) {     listener = new tcplistener(system.net.ipaddress.parse(ipstring), port);   }   listener.start();   while (!abortlistener) {     try {       using (var client = listener.accepttcpclient()) {         // ... 

the rest of code left out, should going.

update:

ok, need error message find out wrong.

when project encounters exception, showing 1 created in project:

screenshot of exception

that gives couple of things start out with.

  • first, box in pic shows dividebyzeroexception caught, code should written handle type of exception:

    try { listener = new tcplistener(stripaddress, intport); } catch (dividebyzeroexception err) { }

no, exception not dividebyzeroexception, need edit code handle type of exception is caught.

  • next comes "handle exception" portion of code: happened? how can you, software programmer, prevent it? if know enough catch type of exception, can rewrite code prevent ever happening.

for case of code example in screenshot, simple solution be:

if (denom != 0) {   answer = num / denom; } else {   answer = -1; } 

but wait! there more.

while stuck looking @ dialog box similar 1 pictured above, can click "view detail..." in actions: section stack trace , inner exception may or may not exist:

view detail screenshot

once have that, should know whole story.

if not know how handle particular exception, search on exception name , message in exception. obviously, else has encountered problem, or microsoft not have written routine catching it.


Comments