الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Multi-thread Web server

مغلق
بدأه bejo في 24 مارس 2006 · 4 رد · 734 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمه الله و بركاته ,

مطلوب مني كتقرير multi-thread web server و ليس لي اي معلومات عن هذا الشيئ غير انه يوجد كود بالجافا ليكون دليل و هو يعمل علي thread واحد فهل يستطيع احد مساعدتي اكون عاجزه عن الشكر و كنت عايزه اعرف نوع the project

fe ASP.net web service & empty web project& ASP.net web application

?? which i should use

جزاكم الله خيرا مقدما

import java.io.*; 
import java.net.*; 
import java.util.*; 

class WebServer{ 

    public static void main(String argv[]) throws Exception  { 

          String requestMessageLine; 
          String fileName; 

          ServerSocket listenSocket = new ServerSocket(6789); 
          Socket connectionSocket = listenSocket.accept(); 

          BufferedReader inFromClient = 
            new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); 
          DataOutputStream outToClient = 
            new DataOutputStream(connectionSocket.getOutputStream()); 

          requestMessageLine = inFromClient.readLine(); 

          StringTokenizer tokenizedLine = 
            new StringTokenizer(requestMessageLine); 

                      if (tokenizedLine.nextToken().equals("GET")){ 

          fileName = tokenizedLine.nextToken(); 

          if (fileName.startsWith("/") == true ) 
                         fileName  = fileName.substring(1); 

                      File file = new File(fileName); 
          int numOfBytes = (int) file.length(); 

          FileInputStream inFile  = new FileInputStream (fileName); 

                      byte[] fileInBytes = new byte[numOfBytes]; 
          inFile.read(fileInBytes); 

          outToClient.writeBytes("HTTP/1.0 200 Document Follows\r\n"); 

          if (fileName.endsWith(".jpg")) 
                  outToClient.writeBytes("Content-Type: image/jpeg\r\n"); 
          if (fileName.endsWith(".gif")) 
                  outToClient.writeBytes("Content-Type: image/gif\r\n"); 

          outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n"); 
          outToClient.writeBytes("\r\n"); 

          outToClient.write(fileInBytes, 0, numOfBytes); 

          connectionSocket.close(); 
                     } 

     else System.out.println("Bad Request Message"); 
  
     } 
}

تم تعديل هذه المشاركة بواسطة bejo في 24 مارس 2006 في 14:20

#2

ووعليكم السلام ورحمه الله وبركاته

أأنا عارف ان الرد متأخر ومعاد تسليم التقرير الاسبوع القادم

هو فيه كتاب انا كنت حطيته علي الموقع بتاع الدفع فيه الكود مكتوب بالسي شارب

بس عشان نفهم الكود احنا هنضرر نقرا الجزء بتاع ال

socket programming

لو فيه اي استفسار انا اسمي علي الفورم

Ahmed Gamal

#3

gazak Allah 7'ayran ya bashmohndes ahmad ana nazlt fe3lan el ketab ele ba3ato bas el code ele fe kan web client

bas ana la2et dars hena lel 2ostaz mo3taz shams fe server w client el7amdolelah bas el moshkela delwa2te en ba3d ma run el server wel client we2felhom eza fataht el server we3mlt ay ta3'yer fe then build bytalal3 el errors de

E:\Walaa\4th year 1st term\Networks 2\report 4\webclient and server multi threaded\WebServer\WebServer\Form1.cs(140): 'System.Net.Sockets.TcpListener.TcpListener(int)' is obsolete: 'Use TcpListener(IPAddress localaddr, int port).'

Could not copy temporary files to the output directory.

The file 'WebServer.exe' cannot be copied to the run directory. The process cannot access the file because it is being used by another process.

sorry 3ala el 2etala w gazakom Allah 7'ayran

#4

Gazakom Allah 7'ayran i've solved it by running the tcp connection each time at new thread

#5

الحمد لله ان المشكله اتحلت بس في الغالب السبب كان ان البرنامج بيتقفل غلط

علي العموم لو فيه اي حاجه انا اقدر اسعدك فيها انا عمري ما هتأخر

هذا الموضوع مغلق.

مواضيع مشابهة