بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim
السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh
After open the program, the initialize has been done in the background. Then, we can click the Listen button and waiting for a client's visit. Before that, user can configure the port number of this web server. The IP address of this server will be displayed in the textbox. The Filename will refer to a web site made by user.
Here uses a global variable b_StopRunning to indicate if this web server is listening on the port and ready for accept a connection. Since the user clicks on Listen button, so it will be set to false.
private void button_Listen_Click(object sender, EventArgs e) { b_StopRunning = false; // Open a new thread to listen to a connection request Thread td_fnServerAcceptConnection = new Thread(new ThreadStart(fnServerAcceptConnection)); td_fnServerAcceptConnection.IsBackground = true; td_fnServerAcceptConnection.Start(); }
// Blocking Way Accept Connection , this blocking function has been delegate to a new thread private void fnServerAcceptConnection() { try { int counter = 0; while (b_StopRunning == false) { counter++; IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName()); server_IPAddress = new IPAddress(ipHostEntry.AddressList[0].GetAddressBytes()); server_Port = System.Convert.ToInt32(this.textBox_ServerPort.Text); // Open a server socket server_Socket = new TcpListener(server_IPAddress, server_Port); server_Socket.Start(); // can use stop() to stop TcpListening fnServerUpdateInfo("Start listening for a client..." + counter.ToString() + "\n"); // get the socket from a client server_myClient = server_Socket.AcceptTcpClient(); server_ClientIP = server_myClient.Client.RemoteEndPoint.ToString(); if (b_StopRunning == true) return; fnServerUpdateInfo("A Client from " + server_ClientIP + " has connected !"); // Get a stream object for reading and writing server_NetworkStream = server_myClient.GetStream(); // Get Information from a Web Browser fnServerMyReadData(); // Upload myWebSite to a Web Brower fnUploadMyWebSite(); // Clean up server_NetworkStream.Close(); server_myClient.Close(); server_Socket.Stop(); } } // try catch (Exception ex) { fnServerUpdateInfo(ex.Message); } } // private void fnServerAcceptConnection() END |
|
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software,
membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI),
Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :
ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin
وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh
Artikel C# :: membuat web server sendiri dengan visual studio, Diterbitkan oleh scodeaplikasi pada Sabtu, 27 Agustus 2016. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software,
membeli source code ,Dengan Cara menghubungi saya
Ke Email: Fajarudinsidik@gmail.com, atau
No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.