Sends a Packet.
(int sock, int length, byte[] data, netadr_t to)
| 148 | * Sends a Packet. |
| 149 | */ |
| 150 | public static void SendPacket(int sock, int length, byte[] data, netadr_t to) { |
| 151 | if (to.type == NetAddrType.NA_LOOPBACK) { |
| 152 | SendLoopPacket(sock, length, data, to); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | if (ip_sockets[sock] == null) |
| 157 | return; |
| 158 | |
| 159 | if (to.type != NetAddrType.NA_BROADCAST && to.type != NetAddrType.NA_IP) { |
| 160 | Com.Error(Defines.ERR_FATAL, "NET_SendPacket: bad address type"); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | try { |
| 165 | SocketAddress dstSocket = new InetSocketAddress(to.getInetAddress(), to.port); |
| 166 | ip_channels[sock].send(ByteBuffer.wrap(data, 0, length), dstSocket); |
| 167 | } catch (Exception e) { |
| 168 | Com.Println("NET_SendPacket ERROR: " + e + " to " + to.toString()); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * OpenIP, creates the network sockets. |
no test coverage detected