ERLEDIGT
NEIN
NEIN
ANTWORTEN
3
3
ZUGRIFFE
503
503
EMPFEHLEN
-
Hallo Leute,
für was ist die bind Methode in der Socket Klasse? Wann und warum muss ich die Methode benutzten?
MFG
-
Wer googlen kann oder die MSDN lesen kann ist klar im Vorteil ... *fg*

Socket-Klasse ----> Bind()Das Leben ist sch**ße ... aber die Grafik ist geil!
-
HI,
die MSDN hab ich schon längst gelesen(sogar in Deutsch).
Bloss wundert mich dass ich in der Klasse TcpListener und bei Java in der Klasse Serversocket kein bind notwendig ist. Macht er das automatisch?
Ist vielleicht nur in der Socket-Klasse ein bind notwendig?
MfG
-
Oh ... sind wir hier im Java-Forum?! Wär mir jetzt neu ... *ggg*

Nun ... in C#.NET ist auch nicht zwingend ein Bind() notwendig, wenn ich hier die MSDN korrekt interpretiere. Sieh Dir mal dieses Beispiel etwas genauer an ... nirgends ein Bind().
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
using System; using System.Text; using System.IO; using System.Net; using System.Net.Sockets; public class GetSocket { private static Socket ConnectSocket(string server, int port) { Socket s = null; IPHostEntry hostEntry = null; // Get host related information. hostEntry = Dns.Resolve(server); // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid // an exception that occurs when the host IP Address is not compatible with the address family // (typical in the IPv6 case). foreach(IPAddress address in hostEntry.AddressList) { IPEndPoint ipe = new IPEndPoint(address, port); Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp); tempSocket.Connect(ipe); if(tempSocket.Connected) { s = tempSocket; break; } else { continue; } } return s; } // This method requests the home page content for the specified server. private static string SocketSendReceive(string server, int port) { string request = "GET / HTTP/1.1\r\nHost: " + server + "\r\nConnection: Close\r\n\r\n"; Byte[] bytesSent = Encoding.ASCII.GetBytes(request); Byte[] bytesReceived = new Byte[256]; // Create a socket connection with the specified server and port. Socket s = ConnectSocket(server, port); if (s == null) return ("Connection failed"); // Send request to the server. s.Send(bytesSent, bytesSent.Length, 0); // Receive the server home page content. int bytes = 0; string page = "Default HTML page on " + server + ":\r\n"; // The following will block until te page is transmitted. do { bytes = s.Receive(bytesReceived, bytesReceived.Length, 0); page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes); } while (bytes > 0); return page; } public static void Main(string[] args) { string host; int port = 80; if (args.Length == 0) // If no server name is passed as argument to this program, // use the current host name as the default. host = Dns.GetHostName(); else host = args[0]; string result = SocketSendReceive(host, port); Console.WriteLine(result); } }
Nur weil er da ist heisst es ja nicht, dass man ihn verwenden muss. Es geht meist auch anders. Manchmal erleichert das Dasein der Bind()-Methode einiges.
Das Leben ist sch**ße ... aber die Grafik ist geil!
Ähnliche Themen
-
Fehler mit bind
Von paul10 im Forum C/C++Antworten: 2Letzter Beitrag: 09.05.09, 12:16 -
Problem mit BIND
Von shrink im Forum Linux & UnixAntworten: 0Letzter Beitrag: 09.09.07, 02:55 -
BIND Fehlermeldung
Von tofa im Forum Hosting & WebserverAntworten: 0Letzter Beitrag: 18.01.06, 17:22 -
Probleme mit DNS (bind 9)
Von juhu im Forum NetzwerkeAntworten: 3Letzter Beitrag: 27.06.03, 10:43 -
Bind Dns [8|9]
Von lexi im Forum NetzwerkeAntworten: 2Letzter Beitrag: 10.02.02, 11:34





Zitieren
Login





