vb.net - TCP/IP Client Connection Issue -
im having trouble tcp client. when client starts form send client.connect request me, when open form accept incoming request both connected , shows connected, when close clients form still shows connected though not.
dim listener new tcplistener(4355) dim client new tcpclient dim message string private sub listen() try listener.start() catch ex exception end try end sub private sub form1_load(sender object, e eventargs) handles mybase.load control.checkforillegalcrossthreadcalls = false 'ip.text = my.settings.ip try dim listening new thread(new threadstart(addressof listen)) listening.start() catch ex exception application.restart() end try sending1.focus() end sub private sub timer2_tick(sender object, e eventargs) handles timer2.tick if client.connected = false label5.text = "disconnected" label5.forecolor = color.red sending1.enabled = false client = listener.accepttcpclient() 'looping accept request end if if client.connected = true label5.text = "connected" label5.forecolor = color.green sending1.enabled = true end if end sub
you can use elseif
.
if client.connected = false label5.text = "disconnected" label5.forecolor = color.red sending1.enabled = false client = listener.accepttcpclient() elseif client.connected = true label5.text = "connected" label5.forecolor = color.green sending1.enabled = true end if
hope :)
Comments
Post a Comment