private void fun_do_udp_sendMsg(int num) { object o = new object(); lock (o) { udp_local = new UdpClient(); try { byte[] b = Encoding.UTF8.GetBytes(msg_send.ToString()); if (b.Length > max_context_bytes) { send_state = SendState.CONTENT_TOO_LONG; return; } udp_local.Connect(end_point_server); udp_local.Send(b, b.Length); send_state = SendState.WAITING_REPLY; } catch (Exception) { send_state = SendState.LOCAL_ERROR; receiveOver(); } } }
public void tcp_sendMsg() { if (tcp_netstream == null) { init(); } try { byte[] sendData = new byte[2048]; sendData = Encoding.Default.GetBytes(msg_send.ToString()); tcp_netstream.Write(sendData, 0, sendData.Length); } catch (Exception ex) { send_state = SendState.SERVER_ERROR; receiveOver(CJLog.LogLevel.COMMON_ERROR, "error: 发送数据时出现错误-" + ex.Message); } }