c# - How to use TCPListener (or other method) to bind to device on the network -
I have a network address of 192.168.xxx.xxx port xxxx. This is a valid address on my network I have tried to use TCPListener to create a connection to the server, but error "error ..... System.Net.Sockets.SocketException: requested address System.Net. DoMind (EndPoint endPointSnapshot, SocketAddress socketAddress) on SystemNet.Sockets.TcpListener.Start (Int32 Backlog) on System.Net.Sockets.Socket.bind (EndPoint localEP) is not valid in reference to Sockets.Socket System.Net on WinMarkTest When I use the myListener.Start () method at .Sockets.TcpListener.start () in Server.Main () C: ..... \ Server.cs: line 49 "
.
Is the "Local Address" server address to use TCPListener?
How and how I can create this connection is within my internal network (on my side of the firewall)
TcpListener will be running on your server waiting for a special connection to the port. A TcpClient will be used to make a connection to the 19 2.168.xxx.xxx:xxxx address. So when you do a listener. Start You are listening to the address and port to make your listener connection, where the listener is running. The address of the local address is the address on which you are listening for the connection.
If you want to create a connection to a remote IP connection, then you will have to check TcpClient an easy test whether you can connect to a SMTP server or something like that.
Edit: - Includes a very raw example to connect and send / receive data to POPDA.
Fixed zero main (string [] args) {stream network stream = faucet; Host hostname = "pop.gmail.com"; Int port = 995; TcpClient Client = New TcpClient (); Memorystream datastream = new memorystream (); {Client.SendTimeout = 15000; Customer RETIVE TIMELINE = 15000; Client.Connect (hostName, port); NetworkStream = New SSL stream (client.GetStream (), true); ((SslStream) networkStream) .AuthenticateAsClient (hostname); Const int chancisy = 256; Int BitesRad = 0; Configure buffer size = 1024; Byte [] buffer = new byte [buffer size]; // should connect connector string message; (Using datestream = new memorystream ()) {do bytesRead = networkStream.Read (buffer, 0, chunky); Datastream.Write (buffer, 0, bytes read); MessageReceived = Encoding.UTF8.GetString (Datastream. ToArray ()); } While (! MessageReceived.EndsWith (EnvironmentalNewLine)); Console.lightline ("response: {0}", encoding. UTF8.GetString (Datastream. ToArray ()); } Buffer = encoding. UTF8.GetBytes ("USER test.net.user@gmail.com \ r \ n"); Network Stream Type (buffer, 0, buffer length); Buffer = new byte [buffer size]; (Using datestream = new memorystream ()) {do bytesRead = networkStream.Read (buffer, 0, chunky); Datastream.Write (buffer, 0, bytes read); MessageReceived = Encoding.UTF8.GetString (Datastream. ToArray ()); } While (! MessageReceived.EndsWith (EnvironmentalNewLine)); Console.lightline ("response: {0}", encoding. UTF8.GetString (Datastream. ToArray ()); }} Hold (exception e) {Console.Write (e); } Finally {if (networkStream! = Null) {networkStream.Dispose (); NetworkStream = null; } If (client! = Null) {if (client.Connected) {client.Client.Disconnect (false); } Client.Close (); Client = null; }} Console. Readkey (); }
Comments
Post a Comment