Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Hardware;
- using Microsoft.SPOT.Net.NetworkInformation;
- using SecretLabs.NETMF.Hardware;
- using SecretLabs.NETMF.Hardware.Netduino;
- namespace wiznetTeste
- {
- public class Program
- {
- public static void Main()
- {
- try
- {
- SecretLabs.NETMF.Net.Wiznet5100 wiznet = new SecretLabs.NETMF.Net.Wiznet5100(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
- NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
- networkInterface.PhysicalAddress = new byte[] { 0x5C, 0x86, 0x4A, 0x00, 0x00, 0x00 };
- networkInterface.EnableStaticIP("192.168.0.59", "255.255.255.0", "192.168.0.1");
- string proxy = "192.168.0.100";
- try
- {
- for (int i = 1; i <= 3; i++)GetWebPage(proxy, "321", 8035);
- }
- catch (SocketException se)
- {
- Debug.Print("SocketException when connecting to " + proxy + ".");
- Debug.Print(
- "If your network uses IPSec, you may need enable the port manually");
- Debug.Print("Socket Error Code: " + se.ErrorCode.ToString());
- Debug.Print(se.ToString());
- }
- }
- catch (Exception exc)
- {
- string err = exc.Message;
- }
- }
- private static void GetWebPage(String Proxy, String URL, Int32 port)
- {
- string server = Proxy;
- using (Socket serverSocket = ConnectSocket(server, port))
- {
- String request = URL;
- Byte[] bytesToSend = Encoding.UTF8.GetBytes(request);
- serverSocket.Send(bytesToSend, bytesToSend.Length, 0);
- }
- }
- private static Socket ConnectSocket(String server, Int32 port)
- {
- IPHostEntry hostEntry = Dns.GetHostEntry(server);
- Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
- socket.Connect(new IPEndPoint(hostEntry.AddressList[0], port));
- return socket;
- }
- private static String GetHostFromURL(string URL)
- {
- int start = URL.IndexOf("://");
- int end = start >= 0 ? URL.IndexOf('/', start + 3) : URL.IndexOf('/');
- if (start >= 0)
- {
- start += 3;
- if (end >= 0)
- return URL.Substring(start, end - start);
- else
- return URL.Substring(start);
- }
- if (end >= 0)
- return URL.Substring(0, end + 1);
- return URL;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement