The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Richard on May 25, 2005, 05:15:22 AM

Title: Chat in mode consola
Post by: Richard on May 25, 2005, 05:15:22 AM
Hello:

How can I build a Chat in mode consola with masm32?
Please help me.

Thank, Richard.
Title: Re: Chat in mode consola
Post by: James Ladd on May 25, 2005, 08:55:20 AM
Do you mean a chat program in the console ?
Maybe start with http://www.jamesladdcode.com and make a plugin ?
Title: Re: Chat in mode consola
Post by: Richard on May 26, 2005, 12:02:20 AM
Thank, but fastutil.exe no found :( and  I don´t undertand good the code.

colaborame please. :U

Thank.
Title: Re: Chat in mode consola
Post by: Richard on May 29, 2005, 06:13:33 AM
???? :(
Title: Re: Chat in mode consola
Post by: Tedd on May 29, 2005, 11:35:46 AM
Richard - look in the masm32 package for examples of console programs :wink
Then search the internet for winsock programs - you can even find chat programs :U
You can't hope to understand the code immediately, you need to learn first :bdg
Keep trying and we'll help you :8)
Title: Re: Chat in mode consola
Post by: Richard on June 01, 2005, 07:41:44 AM
 :U Thank Tedd.

Now, I have the server but the client no found :(

This is the code:

;Inicializa el DLL WindSock v1.1
    invoke WSAStartup,0101h,ADDR wsaData 
    invoke socket,AF_INET,SOCK_STREAM,0
    mov s1,eax   
    mov ax,AF_INET
    mov sin1.sin_family,ax
    invoke htons,Port
    mov sin1.sin_port,ax
    mov AdressIP, input("IP:")
    invoke inet_addr, addr AdressIP                >>>>>>>>>>>>>>>>    No fount, why?
    mov sin1.sin_addr,eax                                >>>>>>>>>>>>>>>>    No fount
   
cmp eax,INADDR_NONE
    print chr$("***Control paso 1***",13,10)   
    je errorIP2   
    cmp eax,SOCKET_ERROR
    print chr$("***Control paso 2*** ",13,10)   
    je errorIP
    jne conexion
    ret     

conexion:
    ;invoke socket,AF_INET,SOCK_STREAM,0
    ;mov s2,eax   
    invoke connect, s2, addr sin2, sizeof sin2
    print chr$("paso 3 ",13,10)
    cmp eax,SOCKET_ERROR
    ;cmp eax,INVALID_SOCKET
    je conexion
    jne enviar
    ret


Title: Re: Chat in mode consola
Post by: thomasantony on June 01, 2005, 08:14:40 AM
Hi,
  I have made  GUI chat pp I used for chatting between the systems on our school LAN while the teacher was not in the lab :bdg . I coded it while I was bored. It probably has lots of bugs. Try it. In server, select Connection-> Wait For Call. For client select COnnection-> Connect.

Thomas :U

[attachment deleted by admin]
Title: Re: Chat in mode consola
Post by: Tedd on June 01, 2005, 02:57:12 PM
This looks okay, but you have a few problems :wink

Quote from: Richard on June 01, 2005, 07:41:44 AM
    mov AdressIP, input("IP:")
    invoke inet_addr, addr AdressIP                >>>>>>>>>>>>>>>>    No fount, why?
    mov sin1.sin_addr,eax                                >>>>>>>>>>>>>>>>    No fount
   
cmp eax,INADDR_NONE
    print chr$("***Control paso 1***",13,10)   
    je errorIP2   
    cmp eax,SOCKET_ERROR
    print chr$("***Control paso 2*** ",13,10)   
    je errorIP

"print" is not one instruction, it's a function - it CAN change the flags AND the value of eax.
So when you do "je .." it's not the same because print changed the state of the zero/equal flag :wink

Try this..

    .
    .
    mov sin1.sin_addr,eax
    push eax
    print chr$("***Control paso 1***",13,10)
    pop eax
    cmp eax,INADDR_NONE
    je errorIP2   

    push eax
    print chr$("***Control paso 2*** ",13,10)
    pop eax
    cmp eax,SOCKET_ERROR
    je errorIP
    .
    .
Title: Re: Chat in mode consola
Post by: Richard on June 01, 2005, 06:49:03 PM
Greetings: 

Thank you very much Thomas  :U
Thanks tedd  :U
Either he forms the application following the suggestions, or envian the client as much as the servant.  since I do so that when envie something to be able to receive it?  Associate the application.  Again thank you very much by all the offered aid

Richard.


[attachment deleted by admin]
Title: Re: Chat in mode consola
Post by: Tedd on June 02, 2005, 12:12:12 PM
Sorry, I don't understand what you mean :(

QuoteEither it forms the application following the suggestions, or sends the client as much as the server.
forms = 'informs/tells' or 'makes' ?
following = 'after' or 'copying' ?
suggestions = 'instructions' or 'signal' ?
sends the client as much as the server = as much as the server sends to the client? or as much as the server can receive?

Quotesince I do so that when send something to be able to receive it?
you want to know how to see when to receive?
Title: Re: Chat in mode consola
Post by: Richard on June 02, 2005, 06:11:08 PM
you want to know how to see when to receive, and how receive, the receive of the program see error.

Thank you tedd. :U
Title: Re: Chat in mode consola
Post by: QvasiModo on June 02, 2005, 07:16:36 PM
¿Querés que probemos en español, y yo traduzco? :wink
Title: Re: Chat in mode consola
Post by: Richard on June 02, 2005, 10:55:24 PM
Gracias QvasiModo  :U

Como configuro la aplicación cliente -  servidor,  para que cuando el cliente envie, el servidor reciba y viceversa y muestre por pantalla. Las funciones estan implementadas pero cuando uso
invoke recv,s1,edit,SIZEOF edit,0   me muestra  error de sockect.

de nuevo muchas gracias.


Richard
Title: Re: Chat in mode consola
Post by: Tedd on June 03, 2005, 12:11:46 PM
Small correction :wink
.data?
edit      db 512 dup (?)
  .
  .
invoke recv, s1,ADDR edit,SIZEOF edit, 0


When you call RECV, the program will wait until there is data. So if there is nothing, it will wait forever :bdg
You can't know when there will be data to receive :(
But you can change it so you don't wait forever:
mov eax,1
mov temp,eax
invoke ioctlsocket, s1,FIONBIO,ADDR temp


So the client (or server) does not know when there is data, you just have to look. If there is, then you will receive it, if not then you will not :wink
Title: Re: Chat in mode consola
Post by: thomasantony on June 04, 2005, 04:01:41 AM
Hi,
   You can used non-blocking sockets and watch for event FD_READ to see whether the socket is ready to be read from.

Thomas :U
Title: Re: Chat in mode consola
Post by: Richard on June 05, 2005, 04:44:02 AM
Hi,

Thomas ¿example?
I don´t undertand.

Thank. :U

Richard.
Title: Re: Chat in mode consola
Post by: Tedd on June 06, 2005, 12:14:26 PM
Thomas means you can use WSAAsyncSelect so you don't have wait each time when you call recv - you will get a 'message' to tell you.
But for now, just keep it simple :wink
Title: Re: Chat in mode consola
Post by: QvasiModo on June 06, 2005, 08:44:59 PM
Quote from: Richard on June 02, 2005, 10:55:24 PM
Gracias QvasiModo  :U

Como configuro la aplicación cliente -  servidor,  para que cuando el cliente envie, el servidor reciba y viceversa y muestre por pantalla. Las funciones estan implementadas pero cuando uso
invoke recv,s1,edit,SIZEOF edit,0   me muestra  error de sockect.

de nuevo muchas gracias.


Richard

Translation:
Quote
How do I configure the client - server application, so that when the client sends, the server receives and viscecersa, and output the data to screen? The functions are implemented but when I use:

invoke recv,s1,edit,SIZEOF edit,0

I get a socket error. Thank you very much again.

Creo que deberías usar esta línea (estoy suponiendo que "edit" es un arreglo de caracteres):

invoke recv,s1,ADDR edit,SIZEOF edit,0

De otra forma, MASM cree que "edit" es un puntero a DWORD y lo lee como tal. Seguramente querías pasarle a recv el puntero al buffer, no los primeros cuatro bytes del mismo. ;)

Salu2
Title: Re: Chat in mode consola
Post by: thomasantony on June 07, 2005, 03:35:45 AM
Hey guys,
  I know only 3 human languges out of which only one is useful here. Would you mind speaking in a language most people can understand  :boohoo: :naughty: :naughty: :green :green :toothy :bdg

Thomas :U
Title: Re: Chat in mode consola
Post by: Tedd on June 07, 2005, 01:11:26 PM
Quote from: thomasantony on June 07, 2005, 03:35:45 AM
Hey guys,
  I know only 3 human languges out of which only one is useful here. Would you mind speaking in a language most people can understand  :boohoo: :naughty: :naughty: :green :green :toothy :bdg

Thomas :U

Qvasi's help is for Richard, not for you :P
Richard's english isn't perfect, so it's easier to get the point across using his language insted of english.
Don't worry, you're not missing out on anything :bdg
Title: Re: Chat in mode consola
Post by: Richard on June 07, 2005, 02:35:20 PM
Hi,
I want to know how to see when to receive?
I want to know how receive?

With the examples  I get a error when  invoke recv,s1,ADDR edit,SIZEOF edit,0 :(

Please help me,

Thank.  :U

Richard

Title: Re: Chat in mode consola
Post by: Tedd on June 07, 2005, 05:24:09 PM
Quote from: Richard on June 07, 2005, 02:35:20 PM
Hi,
I want to know how to see when to receive?
I want to know how receive?

With the examples  I get a error when  invoke recv,s1,ADDR edit,SIZEOF edit,0 :(

Please help me,

Thank.  :U

Richard


I told you - you do not know when.
If you recv but there is nothing, then it will wait until there is something.
If you get an error, then there is something wrong in a different place :wink

What is the error you have??
Title: Re: Chat in mode consola
Post by: Richard on June 07, 2005, 06:56:19 PM
    invoke recv,s2,ADDR RecBuff,SIZEOF RecBuff,0
    cmp eax,SOCKET_ERROR
     je errorecibe
   
    The program jump to the error when cmp eax, SOCKECT_ERROR
Title: Re: Chat in mode consola
Post by: QvasiModo on June 07, 2005, 08:36:29 PM
@Thomas: Don't worry, when I post something I want you to read I'll do it in english ::) :bg

@Richard: Can we see the code where you create the socket?
Title: Re: Chat in mode consola
Post by: Richard on June 07, 2005, 11:14:21 PM
QvasiModo gracias por ayudarme :U

Richard





[attachment deleted by admin]
Title: Re: Chat in mode consola
Post by: Phil on June 07, 2005, 11:17:19 PM
I can't believe that someone objected to clear communication after all the ones and zeros we pass along here! I enjoyed seeing the Spanish, I'd guess it was, and even understood some of it! Especially the Gracias! I'm almost fluent in American-eze, understand most English, some Australian ... but I always enjoy seeing other languages! Frankly though, I just don't understand how those symbolic languages like Chinese work but they certainly have some beautiful characters!
Title: Re: Chat in mode consola
Post by: Tedd on June 08, 2005, 11:59:14 AM
Richard: I'm afraid you have many errors in the program. I think you need to read more about winsock programming to understand better :wink


What is the purpose of socket 's1' ?
Title: Re: Chat in mode consola
Post by: Richard on June 08, 2005, 02:42:41 PM
s1 is a variable type socket. With the that it establishes the conexion initial.

s1        SOCKET ?
Title: Re: Chat in mode consola
Post by: thomasantony on June 09, 2005, 10:37:59 AM
Hi Richard,
   How did you define the buffer 'edit'? You should do something like the one below

.data?
edit db 255 dup(?) ; reserve 255 bytes for recieving the data. Also if you use recv directly, it will hang your program forever, Yu can also use the sleect function to wait for a specific time interval after which the program stops waiting for data. Read the winsock tutorial at

http://www.madwizard.org/

It will help you a lot

Thomas :U
Title: Re: Chat in mode consola
Post by: Tedd on June 10, 2005, 01:23:35 PM
Richard: it's obvious you don't really understand the code you have 'written.'
Using sockets is not very simple, but it is not that difficult when you understand how it works. But you do need to try before you can understand it - which means reading a little more than stealing from examples on the web.
I think you have had too much help, and are not really trying.



This thread should be closed.
Title: Re: Chat in mode consola
Post by: Richard on June 10, 2005, 08:42:31 PM
Thank  :U

I am studying  winsock32 and socket´s.
Title: Re: Chat in mode consola
Post by: Richard on June 14, 2005, 07:58:07 PM
thanks for the help, but now we need something
in console we are capturing something to send to the server, but when the program capture something, it send "@:"
the capture is in the line 149 of client.asm
in the zip ared the client and the server.

Thanks for all

[attachment deleted by admin]
Title: Re: Chat in mode consola
Post by: Tedd on June 15, 2005, 11:49:33 AM
You're getting confused when using ADDR :P
txtinput does not want ADDR :wink

siguenv:   

    .
    .
    invoke send,[s2],ADDR txtinput,SIZEOF txtinput,0


should be...

    invoke lstrlen, txtinput
    invoke send,[s2],txtinput,eax,0


Remember txtinput IS the address, so 'ADDR txtinput' means "the address of the address of the text"
This also means SIZEOF will not work - you need to see how long the string is (lstrlen)


There is a small 'error' in the server when it receives messages, but I'll leave you to work that one out :U
Title: Re: Chat in mode consola
Post by: Richard on June 15, 2005, 10:31:05 PM
Tedd, thank you very much :U

Richard.
Title: Re: Chat in mode consola
Post by: Richard on June 16, 2005, 06:12:30 AM
How clear the buffer when recive? :(

EXAMPLE

rec:Hello World
rec:whereWorld
rec:byere World

Title: Re: Chat in mode consola
Post by: Tedd on June 16, 2005, 10:42:50 AM
 :bdg You found that bug :U

After the server does recv, you need to add 0 (zero) to the end of the string.


invoke recv .........
lea ecx,[recvBuff]
mov BYTE PTR [eax+ecx],0



But check if recv returned SOCKET_ERROR first :wink
Title: Re: Chat in mode consola
Post by: Richard on June 17, 2005, 03:32:35 AM
Ok Tedd, thank. :U

Richard.