زکات علم

زَکاةُ العِلمِ أن تُعَلِّمَهُ عِبادَ اللّه‏ِ امام باقر (ع)
زکات علم

مطالبی در زمینه کامپیوتر و علاقه مندی های شخصی من مطالب این وبلاگ غالبا مطالبی ست که در جای جای اینترنت کتاب یا دانشته های شخصی خودم می باشد که به عنوان مرجعی برای رجوع دوباره در اینجا جمع آوری شده اند .
ehsunitd.ir personal website

پیوندها

۸ مطلب با موضوع «برنامه نویسی» ثبت شده است

«1» port چیست‌؟                                                                                                                                                              فهرست مطالب

بطور کلی هر کامپیوتر  ( به ازای هر کارت شبکه اش ) یک IP دارد، که از طریق این IP‌ می توان به ماشین فوق دسترسی پیدا نمود. این آدرس ( IP ) به 653535 پورت ( PORT ) تقسیم می شود. PORT یک مفهوم منطقی است که به کمک آن می توان بطور همزمان با چندین ماشین دیگر، ارتباط برقرار نمود.

PORT ها به دو گروه رزرو شده (پورت های بین 1 تا 1024) و غیر رزرو شده (سایر پورت ها) تقسیم می شوند. پورت های رزرو شده برای کاربردهای استاندارد مورد استفاده قرار می گیرند. مانند :

 

USAGE

PORT NUMBER

SMTP

25

HTTP

80

POP

110

News Server

119

 

 

در برنامه های Server/ Client از PORT های غیر رزرو شده که آزاد باشند ( مورد استفاده سایر برنامه ها نباشند) می توان جهت برقراری ارتباطات مورد نیاز، استفاده نمود. یعنی می تواند به ازای هر پورت با یک برنامه ارتباط برقرار کند.

 

TCP or UDP Port

 

======================================

«2» socket چیست؟                                                                                                                                                          فهرست مطالب

سوکت یک ارتباط قابل اطمینان جهت انتقال داده ها بین دو host (ماشین مورد نظر) می باشد. سوکت، برنامه نویسان را از پیچیده گی های فرآیند برقراری ارتباط بین دو ماشین مانند جزئیات کد کردن بسته ها، فرآیند ارسال داده ها در شبکه، ارسال مجدد بسته های خراب و ... دور می سازد و برنامه نویسان به راحتی قادر به توسعه برنامه ها یتحت شبکه می باشند.

یک سوکت در حقیقت ترکیبی از IP یا  HostName و یک شماره پورت ( Port Number ) از آن IP می باشد.

بطور کلی یک سوکت چهار عمل اصلی زیر را انجام می دهد:

    «1» اتصال به ماشین راه دور

    «2» ارسال داده ها

    «3» دریافت داده ها

    «4» بستن یا خاتمه اتصال

توجه به این نکته مهم می باشد که یک سوکت در یک زمان فقط قادر است تا فقط با یک ماشین (host) ارتباط برقرار کند.

با توجه به تعاریف فوق، می توان به راحتی تفاوت PORT و SOCKET‌ را درک نمود.

======================================

   «3» پروتکل Transmission Control Protocol )    TCP )                                                                                                              فهرست مطالب

پروتکلی برای انتقال داده ها (سرویس ها) بین دو ماشین با ضریب اعتماد بالا می باشد. چنین ارتباطی (بین دو نقطه) را Unicast می نامند. ‌ TCP پروتکل اتصال گرا ( Connection - Oriented ) است یعنی ارتباط برقرار شده بین کلاینت و سرور تا پایان روند انتقال اطلاعات باقی می ماند. این پروتکل در مواردی که اطمینان از انتقال صحیح داده ها بین مبدا و مقصد بسیار مهم است ( مانند زمان دانلود کردن داده ها) مورد استفاده قرار می گیرد. در چنین حالتی کامپیوتر مقصد با دریافت صحیح هر بسته از مبدا یک Acknowledgment‌ به منظور اطلاع از دریافت صحیح و بی عیب به ماشین مبدا ارسال می کند. اگر پیغام اعلام وصول فوق به مبدا نرسد، مبدا دوباره بسته را ارسال می کند.

======================================

   «4» پروتکل User Datagram Protocol )    UDP )                                                                                                                       فهرست مطالب

پروتکل فوق یک پروتکل بدون اتصال (Connection - Less) می باشد. این پروتکل امکان توزیع داده ها را با سرعت بالا تضمین می کند، ولی هیچ تضمینی در جهت صحت ارسال داده ها و دریافت آنها توسط ماشین مقصد ارائه نمی دهد. بر اساس شرایط این پروتکل اگر در روند انتقال اطلاعات مشکلی پیش آید و بسته ارسال شده به صورت کامل به مقصد نرسد،بسته فوق مجددا برای کامپیوتر مقصد ارسال نخواهد شد.

«نکته» از پروتکل فوق به منظور انتقال داده ها به چندین ماشین با استفاده از BroadCast‌ و یا MultiCast استفاده می شود.

به عنوان مثال، در سایتهایی که اقدام به پخش موسیقی از طریق اینترنت می نمایند، از این پروتکل استفاده می شود. در بعضی لحظات در حین گوش دادن به موسیقی متوجه قطع و وصل شدن یا مکث در پخش موسیقی می شویم. علت این امر نرسیدن یک یا چند بسته از بسته های ارسالی می باشد.

======================================

«5» تفاوت serverSocket و datagramSocket چیست؟                                                                                                             فهرست مطالب

بسته به نوع برنامه ای که ایجاد می کنیم، می توان از datagramSocket‌ یا  serverSokect استفاده نماییم. اگر برنامه ما بر مبنای پروتکل UDP باشد ازdatagramSocket‌  و اگر بر مبنای پروتکل TCP باشد از serverSokect استفاده می کنیم. همانطور که گفته شد، پروتکل TCP جهت ارسال داده ها همراه با تضمین موفقیت آمیز بودن عمل انتقال مانند دانلود و از پروتکل UDP جهت ارسال داده ها با سرعت بالا، اتصال به چند ماشین به طور همزمان و بدون تضمین موفقیت آمیز بودن عمل انتقال مانند کاربردهای RealTime‌  از جمله ویدئو کنفرانس، Internet TV و ... استفاده می شود.

هر دو Socket فوق در سمت ماشین سرور ایجاد می شوند. زمانی که یک ماشین سرور بخواهد از طریق یکی از پورتهایش منتظر رسیدن درخواست اتصال یک کلاینت شود (  در اصطلاح در حال Listen کردن است) ابتدا باید یک سوکت از یکی از نوع های فوق ایجاد کند. سپس پورت مورد نظر را به آن متصل ( Bind ) نموده و به حالت انتظار فرو می رود.

 «نکته» اگر شماره پورتی که می خواهیم با serverSocket مورد نظرمان Bind‌ کنیم، توسط سوکت دیگری در حال استفاده باشد، با پیغام خطای زیر مواجه می شویم.

java.net.BindException

======================================

   «6» بررسی روند برقراری ارتباط بین کلاینت و سرور                                                                                                                   فهرست مطالب 

در برنامه های کلاینت/سروری یا اصطلاحا برنامه نویسی تحت Socket‌ در جاوا، روند برقراری ارتباط بین برنامه کلاینت و برنامه سرور بصورت زیر می باشد:

«1» ابتدا برنامه سرور بر روی ماشین خود اجرا شده و پورتی که در برنامه جهت دریافت درخواست های کلاینت تعیین گردیده است، گوش می دهد. همانطور که گفته شد در این مرحله، برنامه سرور باید یک سوکت از نوع serverSocket یا datagramSocket‌ ایجاد نماید.

«2» برنامه کلاینت اجرا شده و با توجه به IP‌ یا HostName‌ سرور و شماره پورتی که سرور به آن گوش می دهد، درخواستی را به سمت سرور و به جهت برقراری ارتباط ارسال می کند.

ارتباط بین کلاینت و سرور

«3» در این مرحله برنامه سرور درخواست کلاینت را از پورت مشخص شده، دریافت می نماید و اگر همه چیز خوب پیش رود و کلاینت مورد تایید سرور قرار بگیرد، برنامه سرور ابتدا یک پورت دیگر را از سمت ماشین سرور به طور خودکار انتخاب کرده و بر اساس آن یک سوکت جدید ایجاد می کند و به برنامه کلاینت اختصاص می دهد.

ارتباط بین کلاینت و سرور

«4» برنامه کلاینت نیز در ماشین کلاینت یک سوکت بر اساس پورتی که از طریق آن با سرور ارتباط برقرار نموده، ایجاد می کند.

پس از انجام چهار مرحله فوق، یک ارتباط دو طرفه که در هر یک از دو سر آن یک سوکت قرار دارد، بوجود آمده و دو برنامه قادر به برقراری ارتباط با یکدیگر می باشد.

«نکته»  در زمان ایجاد سوکت در برنامه کلاینت، نیازی نیست که برنامه کلاینت پورتی با شماره یکسان نسبت به شماره پورت برنامه سرور انتخاب کند.

 

 

کلید واژه: 

برنامه نویسی سوکت ، Socket چیست ، کار با سوکت ها در جاوا ، ارتباط کلاینت ( Client ) و سرور ( Server ) از طریق سوکت ( Socket )

  

  • ehsan gholami

Setting up Code::Blocks and MINGW, A Free C and C++ Compiler, on Windows

Step 1: Download Code::Blocks

  • Go to this website: http://www.codeblocks.org/downloads
  • Follow the link to "Download the binary release" (direct link)
  • Go to the Windows 2000 / XP / Vista / 7 section
  • Look for the file that includes mingw in the name. (The name as of this writing was codeblocks-10.05mingw-setup.exe; the 10.05 may be different).
  • Save the file to your desktop. It is roughly 74 megabytes.

Step 2: Install Code::Blocks

  • ehsan gholami

به نام خدا




چگونه خود را برای مسابقات ACM آماده کنیم ؟!!



سلام 

مدت ها بود که خودم دنبال مطلب جامع و خوبی در این رابطه بودم . سایت های زیادی رو سر زدم و مطالب زیادی رو دیدم ولی هیچ کدوم مثل مطلب زیر نبود . 

این مطلب رو به تمامی کاربران سایت برنامه نویس تقدیم می کنم .
امیدوارم که همگی ما در این عرصه موفق بشیم.

  • ehsan gholami

Write a program to multiply two matrices using thread.

  • ehsan gholami
/* The ' N - Queens ' / Eight Queens Problem :
Here are my solutions to the N-Queens / 8 queens Problem . There are three solutions here .
1. A solution by simple Backtracking / Recursion . (The only array used in this solution is a 1-d array)
2. A solution to the N-Queens / Eight Queens Problem WITHOUT RECURSION . (Using Stacks )
3. Another recursive function with better ( but vague ) heuristics .
The heuristic was completely my own (as far as I know ) , but a bit arbitrary to some extent .
Anyway , I was glad to see that it produced results pretty quickly uptil N = 70 or so .
( That's on a AMD K-6 Machine with 128 MB Ram. )

IMPORTANT , PLEASE READ ::::
  • ehsan gholami

conio جز سرآیند های استاندارد ANSI نیست. لذا در Linux وجود ندارد. همانطور که حدس زدید این هدر فقط در محصولات بورلند وجود دارد. اگر منظور شما از توابع مهم توابعی مانند توابع کار با کرسر است از ncurses.h یا curses.h استفاده کنید

(اطلاعات بیشتر

(http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/)).

البته انتخاب های دیگری مانند

libconio (http://sourceforge.net/projects/libconio) و

Linux-conio (http://sourceforge.net/projects/linux-conioh)

را نیز می توانید تست کنید.

بدیهیست که dos.h نیز در لینوکس وجود ندارد اما اگر نیازتان را بنویسید شاید بتوان جایگزین دیگری معرفی کرد.

  • ehsan gholami

راهنمای طراحی قالب وبلاگ و کدهای بلاگفا

کاربران بلاگفا این توانایی را دارند که علاوه بر امکان انتخاب قالب وبلاگ خود  از فهرست قالبهای آماده در بلاگفا ، بر اساس سلیقه و نیاز خود شکل و قالب وبلاگ خود را تغییر دهند و یا قالب جدیدی برای وبلاگ خود طراحی کنند.
قالبهای وبلاگ مجموعه ای  از کدهای HTML و بلاکها و کدهای مخصوصی هست که جایگاه عناصر مختلف وبلاگ مانند ایمیل، نام نویسنده یا نام وبلاگ را مشخص میکنند.هنگام مشاهده وبلاگ،خوانندگان به جای کدهای وبلاگ مقدار واقعی آنها (مثلا نام نویسنده) را خواهند دید.
تگها و کدهایی که بلاگفا آنها را پشتیبانی میکند به شرح زیر میباشد.

  • ehsan gholami

Interpreter (computing)

From Wikipedia, the free encyclopedia

In computer science, an interpreter is a computer program that executes, i.e. performs, instructions written in a programming language. An interpreter generally uses one of the following strategies for program execution:

  1. parse the source code and perform its behavior directly
  2. translate source code into some efficient intermediate representation and immediately execute this
  3. explicitly execute stored precompiled code[1] made by a compiler which is part of the interpreter system

Early versions of the Lisp programming language and Dartmouth BASIC would be examples of the first type. PerlPythonMATLAB, and Ruby are examples of the second, while UCSD Pascal is an example of the third type. Source programs are compiled ahead of time and stored as machine independent code, which is then linked at run-time and executed by an interpreter and/or compiler (for JIT systems). Some systems, such as Smalltalk, contemporary versions of BASICJava and others may also combine two and three.

While interpretation and compilation are the two main means by which programming languages are implemented, they are not mutually exclusive, as most interpreting systems also perform some translation work, just like compilers. The terms "interpreted language" or "compiled language" signify that the canonical implementation of that language is an interpreter or a compiler, respectively. A high level language is ideally an abstraction independent of particular implementations.

History[edit]

The first interpreted high-level language was probably Lisp. Lisp was first implemented by Steve Russell on an IBM 704 computer. Russell had read John McCarthy's paper, and realized (to McCarthy's surprise) that the Lisp eval function could be implemented in machine code.[2] The result was a working Lisp interpreter which could be used to run Lisp programs, or more properly, "evaluate Lisp expressions".

Advantages and disadvantages of using interpreters

Programs are usually written in high level code, which has to be converted into machine code for the CPU to execute it. This conversion is done by either a compiler or an interpreter. A compiler makes the conversion just once, while an interpreter typically converts it every time a program is executed (or in some languages like early versions of BASIC, every time a single instruction is executed).[citation needed]

Development cycle

During the software development cycle, programmers make frequent changes to source code.[citation needed] When using a compiler, each time a change is made to the source code, they must wait for the compiler to translate the altered source files and link all of the binary code files together before the program can be executed. The larger the program, the longer the wait. By contrast, a programmer using an interpreter does a lot less waiting, as the interpreter usually just needs to translate the code being worked on to an intermediate representation (or not translate it at all), thus requiring much less time before the changes can be tested.[citation needed]

Distribution[edit]

compiler converts source code into binary instruction for a specific processor's architecture, thus making it less portable. This conversion is made just once, on the developer's environment, and after that the same binary can be distributed to the user's machines where it can be executed without further translation. A cross compiler can generate binary code for the user machine even if it has a different processor than the machine where the code is compiled.

An interpreted program can be distributed as source code. It needs to be translated in each final machine, which takes more time but makes the program distribution independent of the machine's architecture. However, the portability of interpreted source code is dependent on the target machine actually having a suitable interpreter. If the interpreter needs to be supplied along with the source, the overall installation process is more complex than delivery of a monolithic executable.[citation needed]

The fact that interpreted code can easily be read and copied by humans can be of concern from the point of view of copyright. However, various systems of encryption and obfuscation exist. Delivery of intermediate code, such as bytecode, has a similar effect to obfuscation, but bytecode could be decoded with a decompiler or disassembler.[citation needed]

Efficiency

The main disadvantage of interpreters is that when a program is interpreted, it typically runs more slowly than if it had been compiled. The difference in speeds could be tiny or great; often an order of magnitude and sometimes more. It generally takes longer to run a program under an interpreter than to run the compiled code but it can take less time to interpret it than the total time required to compile and run it. This is especially important when prototyping and testing code when an edit-interpret-debug cycle can often be much shorter than an edit-compile-run-debug cycle.[citation needed]

Interpreting code is slower than running the compiled code because the interpreter must analyze each statement in the program each time it is executed and then perform the desired action, whereas the compiled code just performs the action within a fixed context determined by the compilation. This run-time analysis is known as "interpretive overhead". Access to variables is also slower in an interpreter because the mapping of identifiers to storage locations must be done repeatedly at run-time rather than at compile time.[citation needed]

There are various compromises between the development speed when using an interpreter and the execution speed when using a compiler. Some systems (such as some Lisps) allow interpreted and compiled code to call each other and to share variables. This means that once a routine has been tested and debugged under the interpreter it can be compiled and thus benefit from faster execution while other routines are being developed.[citation needed] Many interpreters do not execute the source code as it stands but convert it into some more compact internal form. Many BASICinterpreters replace keywords with single byte tokens which can be used to find the instruction in a jump table. A few interpreters, such as the PBASIC interpreter, achieve even higher levels of program compaction by using a bit-oriented rather than a byte-oriented program memory structure, where commands tokens occupy perhaps 5 bits, nominally "16-bit" constants are stored in avariable-length code requiring 3, 6, 10, or 18 bits, and address operands include a "bit offset". Many BASIC interpreters can store and read back their own tokenized internal representation.

An interpreter might well use the same lexical analyzer and parser as the compiler and then interpret the resulting abstract syntax tree.

Regress

Interpretation cannot be used as the sole method of execution: even though an interpreter can itself be interpreted and so on, a directly executed program is needed somewhere at the bottom of the stack because the code being interpreted is not, by definition, the same as the machine code that the CPU can execute.[3][4]

Variations

Bytecode interpreters

There is a spectrum of possibilities between interpreting and compiling, depending on the amount of analysis performed before the program is executed. For example, Emacs Lisp is compiled tobytecode, which is a highly compressed and optimized representation of the Lisp source, but is not machine code (and therefore not tied to any particular hardware). This "compiled" code is then interpreted by a bytecode interpreter (itself written in C). The compiled code in this case is machine code for a virtual machine, which is implemented not in hardware, but in the bytecode interpreter. The same approach is used with the Forth code used in Open Firmware systems: the source language is compiled into "F code" (a bytecode), which is then interpreted by a virtual machine.[citation needed]

Control tables - that do not necessarily ever need to pass through a compiling phase - dictate appropriate algorithmic control flow via customized interpreters in similar fashion to bytecode interpreters.

Abstract Syntax Tree interpreters[edit]

In the spectrum between interpreting and compiling, another approach is transforming the source code into an optimized Abstract Syntax Tree (AST) then executing the program following this tree structure, or using it to generate native code Just-In-Time.[5] In this approach, each sentence needs to be parsed just once. As an advantage over bytecode, the AST keeps the global program structure and relations between statements (which is lost in a bytecode representation), and when compressed provides a more compact representation.[6] Thus, using AST has been proposed as a better intermediate format for Just-in-time compilers than bytecode. Also, it allows to perform better analysis during runtime.

However, for interpreters, an AST causes more overhead than a bytecode interpreter, because of nodes related to syntax performing no useful work, of a less sequential representation (requiring traversal of more pointers) and of overhead visiting the tree.[7]

Just-in-time compilation

Further blurring the distinction between interpreters, byte-code interpreters and compilation is just-in-time compilation (or JIT), a technique in which the intermediate representation is compiled to native machine code at runtime. This confers the efficiency of running native code, at the cost of startup time and increased memory use when the bytecode or AST is first compiled. Adaptive optimization is a complementary technique in which the interpreter profiles the running program and compiles its most frequently executed parts into native code. Both techniques are a few decades old, appearing in languages such as Smalltalk in the 1980s.[8]

Just-in-time compilation has gained mainstream attention amongst language implementers in recent years, with Java, the .NET Framework and most modern JavaScript implementations now including JITs.[citation needed]

Applications[edit]

Punched card interpreter[edit]

The term "interpreter" often referred to a piece of unit record equipment that could read punched cards and print the characters in human-readable form on the card. The IBM 550 Numeric Interpreter and IBM 557 Alphabetic Interpreter are typical examples from 1930 and 1954, respectively.[citation needed]

  • ehsan gholami