vb.net - Socket programming over internet -
i making simple chat system using socket programming technique in vb.net . works fine on local network how use on internet .. try port forwarding on router ... may way wrong . please tell me correct way port forwarding .. , tell me how connect client server ??? have use public ip of server system ???
the server side code :
imports system.net.sockets module module1 sub main() console.writeline("") dim clientlistener new tcplistener(12380) clientlistener.stop() clientlistener.start() console.writeline("") dim mysocket socket = clientlistener.acceptsocket() console.writeline("") dim recievebuff(225) byte mysocket.receive(recievebuff, recievebuff.length, socketflags.none) dim str string = system.text.encoding.ascii.getstring(recievebuff, 0, recievebuff.length).trim(microsoft.visualbasic.chrw(0)) while not str.startswith(".") console.writeline(str) mysocket.receive(recievebuff, recievebuff.length, socketflags.none) str = system.text.encoding.ascii.getstring(recievebuff, 0, recievebuff.length).trim(microsoft.visualbasic.chrw(0)) end while console.writeline("") clientlistener.stop() end sub end module
and client side code : (those both console applications)
imports system.net.sockets imports system.io module module1 sub main() try console.writeline("connecting localhost ") dim serverlistener new tcpclient("192.168.1.103", 12380) dim readstream stream = serverlistener.getstream serverlistener.sendbuffersize = 256 console.writeline("input lines:") dim str string = console.readline() while 370 dim sendbuff byte() = system.text.encoding.ascii.getbytes(str) readstream.write(sendbuff, 0, sendbuff.length) if str.startswith(".") goto done end if str = console.readline() end while done: console.writeline("done") catch exp exception console.writeline("exception: " + exp.tostring()) end try end sub end module
you need use public ip if client outside of lan.
Comments
Post a Comment