Entrar
¿Nuevo usuario? Inscribirme
squeakRos
? ¿Ya estás suscrito? Entra a Yahoo!

Consejos

¿Sabías que...?
Podés hacer búsquedas de antiguos mensajes del grupo.

Mensajes

  Mensajes Ayuda
Avanzado
Ayuda importante para los alumnos subscriptos a la lista   Lista de mensajes  
Responder | Reenviar Mensaje #513 de 3342 |
Chicos:
Aqui les mando una ayuda importante.
Parece ser que el buffer de recepción no se vaciara despues de leer cada
dato transmitido , probe´con Delay de distintos valores y no mejoró.
Así que como la idea original era hacer una simulación sencilla de Token,
les agrego este .cs.
Vean que han sido modificados el cliente y el server para que el server
envie un Character cr despues de cada mensaje (Si lo pensamos, no es tan
absurdo, despues de todo es un fin de linea en cualquier texto ASCII)
Obviamente, como puede haber varios mensajes , hay que parsearlos (vean el
findToken del cliente).
No les hice la lógica de cuando hay que mandar la lista de mensajes
acumulados al cliente en cuestion, laburen algo.
Recuerden:
Tienen toda esta semana y la próxima para consultarme por mail o en
cualquiera de los horarios.
A domicilio, ya saben la tarifa, las chichs una torta , los varones un
asado, (o al revés, no discrimino).

Buen domingo.
Edgar



Dom, 31 de Oct, 2004 10:13 am

edgardec2001
Sin conexión Sin conexión
Enviar correo Enviar correo

'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 31 October
2004 at 6:59:12 am'! Object subclass: #RemoteClient instanceVariableNames:
'socket serverName' classVariableNames: '' poolDictionaries: '' category:
'RemoteExperiments'! Object subclass: #RemoteServer instanceVariableNames:
'socket' classVariableNames: '' poolDictionaries: '' category:
'RemoteExperiments'! Object subclass: #VNCServer instanceVariableNames: 'port
process ear socketList activeClient maxClient mensaje listaMensajes misClientes'
classVariableNames: '' poolDictionaries: '' category: 'RemoteExperiments'!
!RemoteClient methodsFor: 'as yet unclassified' stamp: 'edc 10/27/2004 06:52'!
initialize Transcript open. Transcript show: 'Probando conexion a red ...
'. Socket initializeNetwork. Transcript show: 'ok'; cr. serverName :=
FillInTheBlank request: 'Nombre server o IPAddress' initialAnswer: 'localhost'.
self newSocket. self nextCommand: (FillInTheBlank request: 'Nombre usuario'
initialAnswer: 'Alumno desconocido')! ! !RemoteClient methodsFor: 'as yet
unclassified' stamp: 'edc 10/27/2004 06:52'! newCommand ^ FillInTheBlank
request: 'Nuevo mensaje' initialAnswer: ''. ! ! !RemoteClient methodsFor: 'as
yet unclassified' stamp: 'edc 4/22/2004 08:03'! newSocket socket _ Socket
newTCP. socket connectTo: (NetNameResolver addressForName: serverName)
port: 8000. socket waitForConnectionUntil: Socket standardDeadline! !
!RemoteClient methodsFor: 'as yet unclassified' stamp: 'edc 10/31/2004 17:46'!
nextCommand: aString | objRec command stream mensajesRecibidos | command :=
aString. [command = 'FIN'] whileFalse: [ (socket isValid and: [socket
isConnected]) ifTrue: [Transcript show: 'Mandamos ' , command; cr.
socket sendData: command.] ifFalse: ["stale connection" socket destroy.
socket := nil]. objRec _ ''. [objRec = 'FIN'] whileFalse: [ [socket
dataAvailable] whileFalse. stream := socket getData. mensajesRecibidos _
stream findTokens: Character cr. mensajesRecibidos do: [ :m| objRec _ m.
Transcript show: 'Respondio ' , objRec printString; cr]]. command :=
self newCommand]! ! !RemoteServer methodsFor: 'as yet unclassified' stamp:
'edc 10/23/2004 07:07'! initialize | command iPAddress s | Transcript open.
Transcript show: 'Starting server'. socket _ Socket tcpCreateIfFail: [^
Transcript show: 'failed']. socket listenOn: 8000. command := 'START'.
[command = 'FIN'] whileFalse: [ socket waitForConnectionUntil: (Socket
deadlineSecs: 30). [socket isConnected] whileTrue: [ socket dataAvailable
ifTrue: [command _ socket getData. iPAddress := NetNameResolver
stringFromAddress: socket remoteAddress. s := String new. s := iPAddress ,
Character tab asString , 'Envio ',command printString. Transcript show:
s;cr. socket sendData: 'OK']]]. socket destroy.! ! !Socket methodsFor:
'receiving' stamp: 'edc 2/15/2004 09:17'! getData | t1 t2 | (self
waitForDataUntil: Socket standardDeadline) ifFalse: [self error: 'getData
timeout']. t1 _ String new: 4000. t2 _ self primSocket: socketHandle
receiveDataInto: t1 startingAt: 1 count: t1 size. ^ t1 copyFrom: 1 to:
t2! ! !Socket methodsFor: 'waiting' stamp: 'jm 3/2/98 18:15'!
waitForConnectionUntil: deadline "Wait up until the given deadline for a
connection to be established. Return true if it is established by the deadline,
false if not." | status | status _ self primSocketConnectionStatus:
socketHandle. [(status = WaitingForConnection) and: [Time millisecondClockValue
< deadline]] whileTrue: [ semaphore waitTimeoutMSecs: (deadline - Time
millisecondClockValue). status _ self primSocketConnectionStatus:
socketHandle]. ^ status = Connected! ! !Socket methodsFor: 'waiting' stamp:
'edc 2/15/2004 09:19'! waitForDataUntil: deadline "Wait up until the given
deadline for data to arrive. Return true if data arrives by the deadline,
false if not." | dataArrived | [self isConnected & (dataArrived := self
primSocketReceiveDataAvailable: socketHandle) not and: ["Connection end and
final data can happen fast, so test in this order " Time
millisecondClockValue < deadline]] whileTrue: [self readSemaphore
waitTimeoutMSecs: deadline - Time millisecondClockValue]. ^ dataArrived! !
!Socket methodsFor: 'waiting' stamp: 'edc 10/5/2004 11:44'!
waitForDisconnectionUntil: deadline "Wait up until the given deadline for the
the connection to be broken. Return true if it is broken by the deadline, false
if not." "Note: The client should know the the connect is really going to be
closed (e.g., because he has called 'close' to send a close request to the other
end) before calling this method. JMM 00/5/17 note that other end can close which
will terminate wait" | extraBytes status | extraBytes := 0. status := self
primSocketConnectionStatus: socketHandle. [((status = Connected) or: [(status =
ThisEndClosed)]) and: [Time millisecondClockValue < deadline]] whileTrue: [
self dataAvailable ifTrue: [extraBytes := extraBytes + self
discardReceivedData]. semaphore waitTimeoutMSecs: (deadline - Time
millisecondClockValue). status := self primSocketConnectionStatus:
socketHandle]. extraBytes > 0 ifTrue: [self inform: 'Discarded ', extraBytes
printString, ' bytes while closing connection.']. ^ status ~= Connected ! !
!Socket methodsFor: 'waiting' stamp: 'edc 10/5/2004 11:42'!
waitForSendDoneUntil: deadline "Wait up until the given deadline for the
current send operation to complete. Return true if it completes by the deadline,
false if not." | sendDone | [self isConnected & (sendDone := self
primSocketSendDone: socketHandle) not "Connection end and final data can
happen fast, so test in this order" and: [Time millisecondClockValue <
deadline]] whileTrue: [ self writeSemaphore waitTimeoutMSecs: (deadline -
Time millisecondClockValue)]. ^ sendDone! ! !Socket methodsFor:
'sending-receiving objects' stamp: 'dgd 2/22/2002 20:28'! getObject "gets a
serialized object from this socket" | encoded object | encoded _ String new
writeStream. [encoded size isZero] whileTrue: [encoded nextPutAll: self
getData]. [self isConnected and: [self dataAvailable]] whileTrue: [encoded
nextPutAll: self getData]. object _ ReferenceStream unStream: encoded contents.
^ object! ! !Socket methodsFor: 'sending-receiving objects' stamp: 'dgd
2/22/2002 20:28'! sendObject: anObject "sends a serialized object to this
socket" | encoded | encoded _ ReferenceStream streamedRepresentationOf:
anObject. self sendData: encoded! ! !Socket class methodsFor:
'remoteExamples' stamp: 'edc 2/15/2004 10:53'! remoteCommClient | newSocket
objRec command serverName | Transcript open. Transcript show: 'starting remote
comm test'; cr. Transcript show: 'initializing network ... '. Socket
initializeNetwork. Transcript show: 'ok'; cr. serverName := '169.254.6.4'.
command := FillInTheBlank request: 'Type remote image command' initialAnswer:
''. newSocket := Socket newTCP. newSocket connectTo: (NetNameResolver
addressForName: serverName) port: 8000. newSocket waitForConnectionUntil:
Socket standardDeadline. Transcript show: 'server start to perform
instructions'; cr. [command = 'FIN'] whileFalse: [Transcript show:
'Command sended is ' , command; cr. newSocket sendObject: command.
newSocket waitForConnectionUntil: (Socket deadlineSecs: 60). [newSocket
isConnected] whileTrue: [newSocket dataAvailable ifTrue: [newSocket
dataAvailable ifTrue: [objRec := newSocket getObject.
Transcript show: 'Resoonse is ' , objRec printString; cr.
command := FillInTheBlank request: 'Type remote image command' initialAnswer:
'']]]]. newSocket closeAndDestroy! ! !VNCServer methodsFor: 'as yet
unclassified' stamp: 'edc 10/30/2004 15:51'! addClient: socket | iPAddress
nombre | iPAddress _ NetNameResolver stringFromAddress: socket remoteAddress.
Transcript show: iPAddress; tab. activeClient _ activeClient + 1.
misClientes at: iPAddress ifAbsent: [ [socket dataAvailable] whileFalse.
nombre _ socket receiveData. Transcript show: nombre; cr. misClientes
at: iPAddress put: nombre. socketList at: activeClient put: socket. ].
activeClient = maxClient ifTrue: [self ringLoop]! ! !VNCServer methodsFor:
'as yet unclassified' stamp: 'edc 10/30/2004 12:13'! mensajesAlCliente self
halt.! ! !VNCServer methodsFor: 'as yet unclassified' stamp: 'edc 4/22/2004
11:09'! newEar | socket | socket _ Socket tcpCreateIfFail: [self error:
'Unable to create a socket']. socket listenOn: port backlogSize: 6. ^ socket!
! !VNCServer methodsFor: 'as yet unclassified' stamp: 'cwp 9/29/2002 19:54'!
newProcess | p | p _ [self serviceLoop] newProcess. p priority: self class
priority. ^ p ! ! !VNCServer methodsFor: 'as yet unclassified' stamp: 'cwp
9/29/2002 17:38'! port: aPort port _ aPort! ! !VNCServer methodsFor: 'as yet
unclassified' stamp: 'edc 10/30/2004 15:31'! procesarMensaje | socket |
socket _ socketList at: activeClient. [socket dataAvailable] whileFalse.
mensaje _ socket receiveData. mensaje = 'LEE' ifTrue: [self mensajesAlCliente
]. mensaje = 'MANDA' ifTrue: [socket sendData: 'Primera palabra nombre, luego
el mensaje'. socket sendData: 'FIN'. [socket dataAvailable] whileFalse.
mensaje _ socket receiveData. listaMensajes add: mensaje]. mensaje = 'FIN'
ifTrue:[socketList at: activeClient put: 'FIN']. ! ! !VNCServer methodsFor:
'as yet unclassified' stamp: 'edc 10/31/2004 06:57'! ringLoop | socket |
[true] whileTrue: [World displayWorldSafely. activeClient _ activeClient \\
maxClient + 1. socket _ socketList at: activeClient. (socket isValid
and: [socket isConnected]) ifTrue: [misClientes valuesDo: [:nombre| socket
sendData: nombre. socket sendData: Character cr]. socket
sendData: 'FIN'. self procesarMensaje] ]! ! !VNCServer methodsFor: 'as yet
unclassified' stamp: 'edc 10/25/2004 07:46'! serviceLoop | conn | conn _ nil.
ear _ self newEar. [true] whileTrue: [[conn isNil] whileTrue: [conn _ ear
waitForAcceptFor: Socket standardDeadline]. conn isConnected ifTrue: [
self addClient: conn. conn _ nil] ifFalse: [self error: 'Accepted
unconnected socket']]! ! !VNCServer methodsFor: 'as yet unclassified' stamp:
'edc 10/30/2004 12:19'! start maxClient := 0. [maxClient between: 1 and: 5]
whileFalse: [maxClient := (FillInTheBlank request: 'Servidor para 1 - 5')
asInteger]. Transcript open. Transcript show: 'Comienza server...';cr.
socketList _ Dictionary new. misClientes _ Dictionary new. listaMensajes _
OrderedCollection new. activeClient _ 0. process ifNil: [Socket
initializeNetwork. process _ self newProcess. process resume] ifNotNil:
[self error: 'Server ya comenzo']! ! !VNCServer methodsFor: 'as yet
unclassified' stamp: 'edc 10/25/2004 07:54'! stop process terminate. process _
nil. ear closeAndDestroy. ear _ nil. Transcript closeAllViews! !
!VNCServer class methodsFor: 'defaults' stamp: 'edc 4/22/2004 10:52'!
defaultPort ^ 8000! ! !VNCServer class methodsFor: 'defaults' stamp: 'cwp
9/29/2002 19:54'! priority ^ Processor lowIOPriority! ! !VNCServer class
methodsFor: 'defaults' stamp: 'edc 10/25/2004 08:07'! start ^ self startOn:
self defaultPort! ! !VNCServer class methodsFor: 'running' stamp: 'cwp
9/29/2002 17:37'! startOn: aPort ^ self new port: aPort; start! ! !VNCServer
class methodsFor: 'running' stamp: 'cwp 11/3/2002 00:20'! stop self
allInstancesDo: [:server | server stop]! ! Smalltalk removeClassNamed:
#RingServer!

Reenviar Mensaje #513 de 3342 |
Desplegar mensajes Autor Ordenar por fecha

Chicos: Aqui les mando una ayuda importante. Parece ser que el buffer de recepción no se vaciara despues de leer cada dato transmitido , probe´con Delay de...
Lic. Edgar J. De Cleene
edgardec2001
Sin conexión Enviar correo
31 de Oct, 2004
10:08 am
Avanzado

Copyright © 2009 Yahoo! de Argentina S.R.L. Todos los derechos reservados.
Política de privacidad - Condiciones del Servicio - Reglas de la comunidad de Yahoo! - Ayuda