Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Blocking and Non-Blocking Loops






Typically, servers will continuously wait for data to appear in a port, and repeatedly do something with that data. The scripts below extend the above example with forever loops to continuously send, receive, and display messages transferred from client(s) to the server. This type of loop forms the basis for most peer-to-peer and client-server network applications. Type " end" in the client program below to quit both the client and server.

Here's the server program (run it first):

(to be completed...)

Here's the client program. Run it only after the server program has been started, and in a separate instance of the RFO Basic interpreter (or on a separate computer):

(to be completed...)

It's important to understand that servers like the one above can interact independently with more than one simultaneous client connection. The " connection" definition waits until a new client connects, and returns a port representing that first client connection. Once that occurs, " connection" refers to the port used to accept data transferred by the already connected client. If you want to add more simultaneous client connections during the forever loop, simply define another " first wait server". Try running the server below, then run two simultaneous instances of the above client:

(to be completed...)

Here's an example that demonstrates how to send data back and forth (both directions), between client and server. Again, run both programs in separate instances of the RFO Basic interpreter, and be sure to start the server first:

(to be completed...)

The following short script combines many of the techniques demonstrated so far. It can act as either server or client, and can send messages (one at a time), back and forth between the server and client:

(to be completed...)

The following script is a complete network instant message application. Unlike the FTP Chat Room presented earlier, the text in this application is sent directly between two computers, across a network socket connection (users of the FTP chat room never connect directly to one another - they simply read from and write to a file on a universally available third party FTP server):

(to be completed...)

Here's an even more compact version (probably the shortest instant messenger program you'll ever see!):

(to be completed...)

And here's an extended version of the above script that uploads your chosen user name, WAN/LAN IP, and port numbers to an FTP server, so that that info can be shared with others online (which enables them to find and connect with you). Connecting as server uploads the user info and starts the application in server mode. Once that is done, others can click the " Servers" button to retrieve and manually enter your connection info (IP address and port), to connect as client. By using different port numbers and user names, multiple users can connect to other multiple users, anywhere on the Internet:

(to be completed...)


Поделиться с друзьями:

mylektsii.su - Мои Лекции - 2015-2024 год. (0.007 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал