private void ComboBoxNetType_SelectedIndexChanged(object sender, EventArgs e) { int index = comboBoxNetType.SelectedIndex; CommNetType.NetType type = NetManager.GetNetTypeByIndex(index); switch (type) { case CommNetType.NetType.UDP_broadcast: ShowEditDesIp(false); SetEditPortTextInListen(false); break; case CommNetType.NetType.UDP_client: ShowEditDesIp(true); SetEditPortTextInListen(false); break; case CommNetType.NetType.UDP_server: ShowEditDesIp(false); SetEditPortTextInListen(true); break; case CommNetType.NetType.TCP_client: ShowEditDesIp(true); SetEditPortTextInListen(false); break; case CommNetType.NetType.TCP_server: ShowEditDesIp(false); SetEditPortTextInListen(true); break; } }
public bool Open(CommNetType.NetType netType, string addr, int port) { if (netType == CommNetType.NetType.UDP_broadcast) { comm = new UdpBroadCastComm(); } else if (netType == CommNetType.NetType.UDP_client) { comm = new UdpClientComm(); } else if (netType == CommNetType.NetType.UDP_server) { comm = new UdpServerComm(); } else if (netType == CommNetType.NetType.TCP_client) { comm = new TcpClientComm(); } else if (netType == CommNetType.NetType.TCP_server) { comm = new TcpServerComm(); } comm.SetOnNetRecvListener(onNetRecvListener); comm.SetOnNetErrorListener(onNetErrorListener); comm.SetOnNetTcpConnectedListener(onNetTcpConnectedListener); return(comm.Open(addr, port)); }
private void OnNetTcpConnectedListener() { int index = comboBoxNetType.SelectedIndex; CommNetType.NetType type = NetManager.GetNetTypeByIndex(index); if (type == CommNetType.NetType.TCP_client || type == CommNetType.NetType.TCP_server) { buttonSend.Enabled = true; } }
private void ButtonOpen_Click(object sender, EventArgs e) { if (netManager.IsOpen()) //IsOPen { //do close netManager.Close(); SetOpenBtnStatus(true); SetNetTypeStatus(true); buttonSend.Enabled = false; } else { //do open string des_ip = textBoxNetDesIp.Text; string des_port = textBoxNetDesPort.Text; if (des_ip == String.Empty) { MessageBox.Show("Please set destination IP !", "Warning"); return; } if (des_port == String.Empty) { MessageBox.Show("Please set destination port !", "Warning"); return; } //net type int index = comboBoxNetType.SelectedIndex; CommNetType.NetType netType = NetManager.GetNetTypeByIndex(index); int port = int.Parse(des_port); if (netManager.Open(netType, des_ip, port)) { SetOpenBtnStatus(false); SetNetTypeStatus(false); if (netType == CommNetType.NetType.UDP_broadcast || netType == CommNetType.NetType.UDP_client || netType == CommNetType.NetType.UDP_server) { buttonSend.Enabled = true; } } } }