c# - TcpClient send/close problem -
do need close connection have messages sent? because whether use send command or use network stream, messages don't processed until close connection. way it's supposed or missing something?
ok here's code.
private void connectbutton_click(object sender, eventargs e) { try { client = new tcpclient(); client.connect(ip, port); netstream = client.getstream(); } catch (exception ex) { messagebox.show(ex.message); } } private void disconnectbutton_click(object sender, eventargs e) { if (client != null) { if (client.connected) { client.close(); client = null; } } } private void sendbutton_click(object sender, eventargs e) { byte[] cmd = tobytearray("bla bla bla"); netstream.write(cmd, 0, cmd.length); netstream.flush(); }
i don't think has method have look.
public static byte[] tobytearray(string str) { system.text.asciiencoding encoding = new system.text.asciiencoding(); return encoding.getbytes(str); }
you using buffered streams, try call .flush method, automatically called when clode invoked.
Comments
Post a Comment