.net - Error when sending data over network? -


i've made small program allows user remotely control home computer computer has internet connection, keep getting error whenever try send test command laptop...

system.argumentnullexception: value cannot null.

parameter name: buffer

at system.net.sockets.networkstream.read(byte[] buffer, int32 offset, int32 size)

at svchost.form1.accept_client() in c:\users\samuel\documents\visual studio\2012\projects\svchost\svchost\form1.vb:line 40

here's code...

imports ste  public class form1 'ps, client_info rich text box...  private serverlistener new net.sockets.tcplistener(9653) 'list incoming connections private serversender new net.sockets.tcpclient 'send data client private bytefromclient() byte 'allows max of 1024 characters client. private bytefromserver() byte 'allows max of 1024 characters server. private stringfromserver string = "" private stringfromclient string = "" private streamfromserver net.sockets.networkstream private streamfromclient net.sockets.networkstream private pendingclient new net.sockets.tcpclient 'client handle private secure new ste.encryption 'encrypt data  private sub form1_formclosing(sender object, e formclosingeventargs) handles me.formclosing     recive.cancelasync() end sub  private sub form1_load(sender object, e eventargs) handles mybase.load     recive.runworkerasync() 'start listening thread end sub  private sub recive_dowork(sender object, e system.componentmodel.doworkeventargs) handles recive.dowork     serverlistener.start() 'start listening incoming information clients     while true         if serverlistener.pending = true             call accept_client()         end if         if recive.cancellationpending = true             exit         end if     loop end sub  private sub accept_client()     try         pendingclient = serverlistener.accepttcpclient         pendingclient.getstream.read(bytefromclient, 0, pendingclient.receivebuffersize) 'error here...         stringfromclient = system.text.encoding.ascii.getstring(bytefromclient)         client_info.text = stringfromclient & vbnewline     catch ex exception         client_info.text = ex.tostring     end try end sub  private sub transmit_dowork(sender object, e system.componentmodel.doworkeventargs) handles transmit.dowork     try         while serversender.connected = false             serversender.connect("127.0.0.1", 9653) 'connect local pc (temp)...         loop         bytefromserver = system.text.encoding.ascii.getbytes(commandtb.text)         streamfromserver.write(bytefromserver, 0, bytefromserver.length) 'write data stream         streamfromserver.flush() 'send data     catch ex exception         msgbox(ex.tostring & vbnewline & ex.innerexception.data.tostring)     end try end sub  private sub send_command_click(sender object, e eventargs) handles send_command.click     transmit.runworkerasync() 'start thread transmit data client end sub end class 

network programming weak area me, i'm not sure if code has correct logic. appreciated.

dim bytefromclient(1024) byte 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -