News:

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

Winsock Relay Server / Client Demo Pkg

Started by tomkane, August 20, 2006, 09:29:19 PM

Previous topic - Next topic

tomkane

The modules included in this zip package are provided as a demo of Winsock capabilities operating in the asychronous mode. There are 2 different modules: a relay server and a relay client. Both modules' main windows are logs of activities as they occur; the log contents may be saved to file.

The relay functionality is quite simple; it's not meant to do anything like IRC. The server module allows clients to:

+ connect to it,
+ log in with a user ID,
+ request a list of users logged in,
+ send a message to another user (or to self), and
+ log out/disconnect

You can run as many relay clients at the same time as you wish; the relay server distinguishes between them internally via the socket and externally via the login user's name.

My purpose in creating this package was to fulfill my own need for a mechanism for interprocess communication that was able to function between multiple modules on the same or different machines (CPUs). This stems partly from past experience with DDE and my desire to avoid its inadequacies.

I also wanted to prove to myself that I could program to the Winsock API in its asynchronous mode.

Plus, there was my experience wandering around searching for good examples in assembler using Winsock: although I found some working examples, I did not find anything along the line of relay server/client modules. It seemed that there was a deficit there, so I probably put more effort into this demo than I would have were I developing solely for my own use.

I also want to mention that, while I found some good assembler examples, I made a lot of use of the algorithms (in 'C') listed in the book "Windows Sockets Network Programming" by Bob Quinn and Dave Shute. Their examples were of an echo server and an FTP client. I used their underlying concepts but had to make significant changes to create the relay functionality.

One algorithmic issue that might bear some clarification is how the relay server sends data to the clients. This is significant insofar as the server does not have any user intervention, i.e., it only responds to messages received from the relay clients. The server must work around the fact that a "send" operation can be blocked at any time by the Winsock processes. Consequently, I found a workable approach to be through queueing all communications from the server, which is done most conveniently with a linked list queue, holding data until all of the data in a queued sendpacket's buffer has been transmitted. All buffered data is held in temporarily allocated memory, which is free'd after the transmission is complete.

A final note: I tested this relay functionality on one machine using the loopback internet address: 127.0.0.1. In addition, my machine is running Windows 98, so the OS is fairly behind times. I would be very grateful to hear from anyone who could test the relay modules on multiple machines -- the more the merrier!

You may be able to tell that I am a former 'C' programmer. I know it shows in the way I code, especially in that I use a lot of stack variables and global data. I really tried to use more registers but eventually ran into the wall of discovery where I realized that every time I used an invoke the data I thought was in the registers was not there afterwards. So I went back to using more stack variables. I'm sure I'll get better at finding the right combination of efficiency and security.

As I implied above, I not only welcome feedback, I encourage it!  :bg

Tom Kane

[attachment deleted by admin]

James Ladd

Tom,

Thankyou for taking the time to share this code.
I'm also sorry my project wasn't ready to assist as a chat server/client would have made a great plugin.

Rgs,James.

Mark_Larson

Tom,


  I tried running it under Windows XP.  The connection to 127.0.0.1 worked.  But when I tried to log in it crashes. I am attacing a pic.



[attachment deleted by admin]
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

tomkane

Mark,

Thanks for letting me know. I'll look at it as soon as I can.

Tom

tomkane

Mark,

I have made a few changes to the attached file. See if these help on the XP platform. Everything was working in your example up to point where the server was receiving the login name. It obviously crashed after some sort of memory overwrite.

There were a few places where the code was doing Alloc's and then initializes with memfill. I wasn't happy with them before 'cause I just felt that there was a chance that odd-sized allocated memory (i.e, that wasn't evenly divisible by 4, such as name strings) might have problems when memfill converted bytes to the fill value. To fix this, I created a macro to round up allocation sizes to the next higher number divisible by 4.

I also spent a lot of wasted time trying to get HideCaret to stop the caret from showing in my edit windows, but it always came back. Any suggestions there would be appreciated.

Please give it another try.

Regards,

Tom

[attachment deleted by admin]

Mark_Larson


  I was able to login without crashing.  Great job :)
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

tomkane

Mark, thanks for the feedback.  :cheekygreen: