Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Navigation;
- using Microsoft.Phone.Controls;
- using Microsoft.Phone.Shell;
- using SocketsTest.Resources;
- using System.Net.Sockets;
- using System.Threading;
- using System.Diagnostics;
- namespace SocketsTest
- {
- public partial class MainPage : PhoneApplicationPage
- {
- Socket _socket = null;
- static ManualResetEvent _clientDone = new ManualResetEvent(false);
- public Boolean _isConnected = false;
- // Constructor
- public MainPage()
- {
- Debug.WriteLine("Application proccessing...\n");
- InitializeComponent();
- Debug.WriteLine("Application started\n");
- // Sample code to localize the ApplicationBar
- //BuildLocalizedApplicationBar();
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- Console.WriteLine("Connection proccessing...\n");
- string result = string.Empty;
- string hostName = "137.135.176.144";
- int portNumber = 1337;
- DnsEndPoint hostEntry = new DnsEndPoint(hostName, portNumber);
- _socket = new Socket(AddressFamily.InterNetwork,
- SocketType.Stream,
- ProtocolType.Tcp);
- SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
- socketEventArg.RemoteEndPoint = hostEntry;
- socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs h)
- {
- result = h.SocketError.ToString();
- _clientDone.Set();
- });
- _clientDone.Reset();
- _isConnected = _socket.ConnectAsync(socketEventArg); // Return "true"
- _clientDone.WaitOne(2000);
- if (_socket != null && _socket.Connected == true)
- {
- Debug.WriteLine("Successful connection =D\n");
- }
- else
- {
- Debug.WriteLine("Connection failed!\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement