News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Winsock problem

Started by RedXVII, January 25, 2006, 12:47:09 PM

Previous topic - Next topic

RedXVII

Hiya,

Ive been learning some winsock stuff - ive managed to successfully send and recieve data then shutdown ok but...

What im doing now is expanding it to making a kind of console chat program to learn more about how winsock works. Trouble im having is with funtions like stdin and getconsoleinput etc. the program code stops and waits for the user to input data right? Well, i want to be able to recieve and display sent data (text from my mate) on the console at the same time as accepting user input (my text) - but the winsock functions arent run while the functions getconsoleinput etc is waiting for a keyboard input. so... kaboom?

How would i go about implementing this - is there a simple way i overlooked? Ive never used it before but perhaps this is a good example for multithreading??

Many Thanks
Red  :U

Tedd

You 'can' do it with mulitple threads, by having one thread the waits for the messages to be received, and the other to send and display, etc.
But it may be simpler to use the WSAAsyncSelect function - which allows you to set it up so that you receive a message each time there is something to receive (and when the connection is closed, and other good things.)
No snowflake in an avalanche feels responsible.

P1

Quote from: RedXVII on January 25, 2006, 12:47:09 PM
Trouble im having is with funtions like stdin and getconsoleinput etc. the program code stops and waits for the user to input data right? Well, i want to be able to recieve and display sent data (text from my mate) on the console at the same time as accepting user input (my text)
When you say 'console', we think DOS box/prompt.  DOS programs are assumed single threaded.  Kind of like a teletype output.

There are chat programs around in MASM32.  But there are programmed to a GUI window and are usually multi-threaded.

Which way do you want to go?  Because the Console/DOS route is going to have it's chalenges.

Regards,  P1  :8)


RedXVII

Ted: Thanks for function name mate - am looking it up right now, if it does what i think youre saying it does, then it will help a treat. (by this i mean, does it send a windows message into the windows message queue for my WndProc?)

P1: eeek, i guess youre right - this is going to have lots of challenges. I was just too lazy to write code to display a chat windows and extra blah and I wanted to learn how winsock works. Its become immediatley apparent that making a window and using dialogue stuff will be easier.

Ive been looking for assembly source code for a chat program - do you know where to find one?

Thanks guys  :U

gabor

Hello!


Some years ago I learned about network programing (TCP/IP). That time I collected some documents on this topic.
I mainly read about Unix solutions, but this link proved to be very usefull:
http://www.hal-pc.org/~johnnie2/winsock.html
For console apps there is a possibility that is called a non-blocking socket (the send and receive does not stop the main program) and asynchronous connection (it is not polling the soket, but getting notified when data is received). The central part of such a console version is the select function.
I wrote this old project in C, there I used the kbhit function for avoiding that the program has to wait for keyboard input. Kbhit returns with true is a key has been hit. So when true I could simply read the input with the raditional getch() function. Now, how does this work in masm console mode, I'm sorry I could not figure it out yet.
Maybe it is easier to create a small window app. I believe the winsock package contains everything to get a port listener thread working. You don't have to create that yourself, you just have to set up the connection properly and prepare your (window) process to be able to handle the messages sent by winsock. This message is defined by the user:
WSAAsyncSelect(theSocket, hwnd, YOUR_SOCKET_MSG, FD_READ | FD_WRITE | FD_CONNECT | ...);

I guess these info is included in the other masm docs about network communication, however I hope I gave some hints. :U

Greets, Gábor

P1

Use 'Search' here on the board.  ThomasAnthony did several examples.

Use Google, and try dolphinz cruechat as some of th keywords.

Regards,  P1  :8)

Samuel

I wrote a tutorial on multi-threading.

Ive also written a consol based chatting program in C++, you can download both of these resources from my site.

www.supercamel.co.nr