//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void connect() throws java.io.IOException public virtual void connect() { openChannel(); if (!socketChannel.Connected && !socketChannel.ConnectionPending) { SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByAddress(destinationIPAddress), destinationPort); socketChannel.connect(socketAddress); } }
public Connect(string ipAddress, string broadcastIpString) : base(ipAddress, broadcastIpString) { this.espFirmwareVersion = new sbyte[] { 0, 0 }; this.hdmiInput = 0; this.displayAnimationEnabled = 0; this.ambientLightAutoAdjustEnabled = 0; this.microphoneAudioBroadcastEnabled = 0; this.irEnabled = 1; this.irLearningMode = 0; this.irManifest = new sbyte[40]; this.emailAddress = ""; this.thingName = ""; this.lightType = 0; this.lightIpAddresses = new InetAddress[10]; this.lightSectorAssignments = new sbyte[150]; this.hueBridgeUsername = ""; this.hueBulbIds = new sbyte[10]; this.hueBridgeClientKey = new sbyte[16]; this.hueBridgeGroupNumber = 0; this.hueBridgeGroupName = ""; this.lightNames = new string[10]; this.sectorData = new sbyte[] { 0 }; this.isDemo = false; this.hueLifxSettingsReceived = false; this.emailReceived = false; this.productId = 4; this.name = "Connect"; sbyte b = 0; while (b < 10) { try { this.lightIpAddresses[b] = InetAddress.getByAddress(new sbyte[] { 0, 0, 0, 0 }); this.hueBulbIds[b] = 0; this.lightNames[b] = ""; b = (sbyte)(b + 1); } catch (UnknownHostException) { } } for (sbyte b2 = 0; b2 < 16; b2 = (sbyte)(b2 + 1)) { this.hueBridgeClientKey[b2] = 0; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void sendICMPEchoResponse(pspsharp.network.protocols.NetPacket packet, pspsharp.network.protocols.EtherFrame frame, pspsharp.network.protocols.IPv4 ipv4, pspsharp.network.protocols.ICMP icmp) throws java.io.EOFException private void sendICMPEchoResponse(NetPacket packet, EtherFrame frame, IPv4 ipv4, ICMP icmp) { bool reachable = false; try { InetAddress inetAddress = InetAddress.getByAddress(ipv4.destinationIPAddress); // Timeout after 1 second reachable = inetAddress.isReachable(null, ipv4.timeToLive, 1000); } catch (UnknownHostException) { } catch (IOException) { } if (reachable) { // See https://en.wikipedia.org/wiki/Ping_(networking_utility) EtherFrame answerFrame = new EtherFrame(frame); answerFrame.swapSourceAndDestination(); IPv4 answerIPv4 = new IPv4(ipv4); answerIPv4.swapSourceAndDestination(); answerIPv4.timeToLive--; // When a packet arrives at a router, the router decreases the TTL FieldInfo. ICMP answerIcmp = new ICMP(icmp); answerIcmp.type = ICMP.ICMP_CONTROL_ECHO_REPLY; answerIcmp.computeChecksum(); answerIPv4.totalLength = answerIPv4.sizeOf() + answerIcmp.sizeOf(); answerIPv4.computeChecksum(); // Write the different headers in sequence NetPacket answerPacket = new NetPacket(BUFFER_SIZE); answerFrame.write(answerPacket); answerIPv4.write(answerPacket); answerIcmp.write(answerPacket); sendPacket(answerPacket); } }
public virtual int sceNetResolverStartAtoN(int rid, int addr, TPointer hostnameAddr, int hostnameLength, int timeout, int retry) { try { sbyte[] bytes = sceNetInet.internetAddressToBytes(addr); InetAddress inetAddress = InetAddress.getByAddress(bytes); string hostName = inetAddress.HostName; hostnameAddr.setStringNZ(hostnameLength, hostName); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNetResolverStartAtoN returning host name '{0}'", hostName)); } } catch (UnknownHostException e) { Console.WriteLine(e); return(SceKernelErrors.ERROR_NET_RESOLVER_INVALID_HOST); } return(0); }
public override void start() { base.start(); Console.WriteLine(string.Format("ProOnline start, server {0}:{1:D}", metaServer, metaPort)); try { broadcastInetAddress = InetAddress.getByAddress(new sbyte[] { 1, 1, 1, 1 }); } catch (UnknownHostException e) { Console.WriteLine("Unable to set the broadcast address", e); } try { loopbackInetAddress = InetAddress.getByName("localhost"); } catch (UnknownHostException e) { Console.WriteLine("Unable to set the loopback address", e); } try { localHostInetAddress = InetAddress.getByName(sceNetApctl.LocalHostIP); } catch (UnknownHostException e) { Console.WriteLine("Unable to set the local address", e); } upnp = new UPnP(); upnp.discoverInBackgRound(); }
public virtual void readHueLifxSettings() { Log.i("Connect", "readHueLifxSettings"); (new Thread(() => { HttpURLConnection httpURLConnection = null; try { httpURLConnection = (HttpURLConnection)(new URL("http://" + Connect.this.Ip + "/api/connect/state")).openConnection(); httpURLConnection.RequestMethod = "GET"; int responseCode = httpURLConnection.ResponseCode; Log.i("Connect", "responseCode " + responseCode); if (responseCode == 200) { StreamReader @in = new StreamReader(httpURLConnection.InputStream); StringBuilder response = new StringBuilder(); while (true) { string inputLine = @in.readLine(); if (string.ReferenceEquals(inputLine, null)) { break; } response.Append(inputLine); } @in.close(); Log.i("Connect", "readHueLifxSettings: " + response.ToString()); try { JSONObject rootObject = new JSONObject(response.ToString()); int tempInt = rootObject.optInt(Connect.JSON_LIGHT_TYPE, -1); if (tempInt != -1) { Connect.this.initLightType(tempInt); } string asciiHex = rootObject.optString(Connect.JSON_LIGHT_IPADDRESSES, null); if (!string.ReferenceEquals(asciiHex, null)) { InetAddress[] ipAddresses = new InetAddress[10]; sbyte[] tempBytes = Connect.asciiHexToByteArray(asciiHex, asciiHex.Length); for (int lightCount = 0; lightCount < 10; lightCount++) { try { ipAddresses[lightCount] = InetAddress.getByAddress(Arrays.CopyOfRange(tempBytes, lightCount * 4, (lightCount * 4) + 4)); } catch (UnknownHostException) { } } Connect.this.initLightIpAddresses(ipAddresses); } string asciiHex2 = rootObject.optString(Connect.JSON_LIGHT_SECTOR_ASSIGNMENTS, null); if (!string.ReferenceEquals(asciiHex2, null)) { Connect.this.initLightSectorAssignments(Connect.asciiHexToByteArray(asciiHex2, asciiHex2.Length)); } string tempString = rootObject.optString(Connect.JSON_HUE_BRIDGE_USERNAME, null); if (!string.ReferenceEquals(asciiHex2, null)) { Connect.this.initHueBridgeUsername(tempString.Trim()); } string asciiHex3 = rootObject.optString(Connect.JSON_HUE_BULB_IDS, null); if (!string.ReferenceEquals(asciiHex3, null)) { Connect.this.initHueBulbIds(Connect.asciiHexToByteArray(asciiHex3, asciiHex3.Length)); } string asciiHex4 = rootObject.optString(Connect.JSON_HUE_BRIDGE_CLIENT_KEY, null); if (!string.ReferenceEquals(asciiHex4, null)) { Connect.this.initHueBridgeClientKey(Connect.asciiHexToByteArray(asciiHex4, asciiHex4.Length)); } int tempInt2 = rootObject.optInt(Connect.JSON_HUE_BRIDGE_GROUP_NUMBER, -1); if (tempInt2 != -1) { Connect.this.initHueBridgeGroupNumber(tempInt2); } string tempString2 = rootObject.optString(Connect.JSON_HUE_BRIDGE_GROUP_NAME, null); if (!string.ReferenceEquals(asciiHex4, null)) { Connect.this.initHueBridgeGroupName(tempString2.Trim()); } string asciiHex5 = rootObject.optString(Connect.JSON_LIGHT_NAMES, null); if (!string.ReferenceEquals(asciiHex5, null)) { string[] lightNames = new string[10]; sbyte[] tempBytes2 = Connect.asciiHexToByteArray(asciiHex5, asciiHex5.Length); for (int lightCount2 = 0; lightCount2 < 10; lightCount2++) { try { lightNames[lightCount2] = (new string(Arrays.CopyOfRange(tempBytes2, lightCount2 * 32, (lightCount2 * 32) + 32), "UTF-8")).Trim(); } catch (IOException) { } } Connect.this.initLightNames(lightNames); } Connect.this.hueLifxSettingsReceived = true; } catch (JSONException) { if (httpURLConnection != null) { httpURLConnection.disconnect(); return; } return; } } else { Log.i("Connect", "readHueLifxSettings, did not receive 200"); } if (httpURLConnection != null) { httpURLConnection.disconnect(); } } catch (IOException e4) { Log.i("Connect", "readHueLifxSettings error: " + e4.ToString()); if (httpURLConnection != null) { httpURLConnection.disconnect(); } } catch (Exception th) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } throw th; } })).Start(); }