public static void ServerStart() { int listenerPort = Config.Ports.FindServer; listener = new UdpClient(listenerPort); serverIP = IPManager.GetLocalIpAddress().ToString(); AcceptClient(); }
public static async void ServerStartAsync() { // Get information for connecting or for later reference int listenerPort = Config.Ports.FindServer; serverIP = IPManager.GetLocalIpAddress(); // Generate the listener server socket listener = new DatagramSocket(); listener.MessageReceived += AcceptClient; // Assumes default inbound buffer size await listener.BindEndpointAsync(new HostName(IPManager.GetLocalIpAddress()), Config.Ports.FindServer.ToString()); }
public static async void StartAsync() { int port = Config.Ports.ClientServerConnection; listener = new StreamSocketListener(); SetSocketSettings(listener.Control); listener.ConnectionReceived += OnConnection; // Bind TCP to the server endpoint HostName serverHostName = new HostName(IPManager.GetLocalIpAddress()); int serverPort = Config.Ports.ClientServerConnection; await listener.BindEndpointAsync(serverHostName, serverPort.ToString()); }
public static void SendFiles(string remoteIP, int port, string[] filepaths) { new Task(async() => { int serverPort = Config.Ports.ClientServerConnection; EndpointPair endpointPair = new EndpointPair(new HostName(IPManager.GetLocalIpAddress()), port.ToString(), new HostName(remoteIP), serverPort.ToString()); StreamSocket socket = new StreamSocket(); await socket.ConnectAsync(endpointPair); Socket_Base_Hololens.SendFilesAsync(filepaths, socket); socket.Dispose(); }).Start(); }
public static void RequestFiles(string serverIP, int port, string receiveDirectory) { new Task(async() => { // Generate the socket and connect to the server StreamSocket socket = new StreamSocket(); int serverPort = Config.Ports.ClientServerConnection; EndpointPair endpointPair = new EndpointPair(new HostName(IPManager.GetLocalIpAddress()), port.ToString(), new HostName(serverIP), serverPort.ToString()); await socket.ConnectAsync(endpointPair); // After awaiting the connection, receive data appropriately ReceiveFilesAsync(socket, receiveDirectory); socket.Dispose(); }).Start(); }
// IPAddress string public static async void FindServerAsync() { string IPString = string.Empty; DatagramSocket clientSocket = new DatagramSocket(); string clientIP = IPManager.GetLocalIpAddress(); clientSocket.MessageReceived += FoundServer; //await clientSocket.BindEndpointAsync(new HostName(IPManager.GetLocalIpAddress()), Config.Ports.FindServer.ToString()); await clientSocket.ConnectAsync(new HostName(IPManager.BroadcastIP), Config.Ports.FindServer.ToString()); DataWriter writer = new DataWriter(await clientSocket.GetOutputStreamAsync(new HostName(IPManager.BroadcastIP), Config.Ports.FindServer.ToString())); byte[] clientIPBytes = CryptographicBuffer.ConvertStringToBinary(clientIP, BinaryStringEncoding.Utf8).ToArray(); writer.WriteBytes(clientIPBytes); }
// IPAddress string public static string FindServer() { string IPString = string.Empty; UdpClient client = new UdpClient(); client.EnableBroadcast = true; int findServerPort = Config.Ports.FindServer; IPEndPoint serverEndpoint = new IPEndPoint(IPAddress.Broadcast, findServerPort); byte[] clientIPBytes = Encoding.UTF8.GetBytes(IPManager.GetLocalIpAddress().ToString()); client.Send(clientIPBytes, clientIPBytes.Length, serverEndpoint); byte[] serverIPBytes = client.Receive(ref serverEndpoint); IPString = Encoding.UTF8.GetString(serverIPBytes); serverIP = IPString; return(IPString); }
public static void RequestFiles(string serverIP, int port, string receiveDirectory) { new Thread(() => { // Generate the socket //TcpClient tcp = new TcpClient(); IPAddress clientIP = IPAddress.Parse(IPManager.ExtractIPAddress(IPManager.CompileNetworkConfigString(port))); TcpClient client = new TcpClient(new IPEndPoint(clientIP, port)); // Connect to the server int serverPort = Config.Ports.ClientServerConnection; //IPAddress serverIP = IPAddress.Any; IPAddress serverIPAddress = IPAddress.Parse(serverIP); client.Connect(serverIPAddress, serverPort); // After awaiting the connection, receive data appropriately Socket socket = client.Client; ReceiveFiles(socket, receiveDirectory); socket.Shutdown(SocketShutdown.Both); socket.Close(); }).Start(); }