Check Out Dave's New game for iPhone and iPod Touch: Smiled Out!

Chat Client/Server Part 1: Network Programming Primer and Packet Base Class

Pages: 1 2 3 4 5 6 7

Blocking Versus Non-Blocking, Threads

Though we have our system defined as we will implement it, there is a further complication that needs to be discussed before we delve into some code. This issue is called “blocking.”

A socket can run in one of two states, blocking or non-blocking. A blocking socket means that when you issue a command to send or receive data, the socket will not return control to the current thread until it successfully completes the operation. This means that if you want to handle multiple connections, do some other processes, or have a responsive user interface while sending and receiving then you had better have a plan for how to deal with a blocking socket.

A non-blocking socket runs in “asynchronous” mode, which means that you can issue a send or receive command, and then a callback or event of some form will be raised when the command completes. During that time, your program will continue its other tasks normally. These sockets are very useful, but since blocking sockets are easier to work with we are going to use the blocking form.

This means that we must plan on using threads in our server (which will come in the next part of this tutorial) in order to handle multiple concurrent connections, as every socket will probably be in a constant send or receive state. This may sound hairy, but threads are actually very easy to implement in the dot net framework.

Pages: 1 2 3 4 5 6 7


Follow Dave on Twitter
  1. [...] See the original post here: Program With Dave » Blog Archive » Chat Client/Server Part 1 … [...]

  2. [...] the original post:  Program With Dave » Blog Archive » Chat Client/Server Part 1 … By admin | category: chat software | tags: dot-net, manifest-itself, p2p-video, result, [...]

  3. [...] Address Already In Use: JVM_Bind:8080″. Now, if you’ve read my sockets tutorial network primer, you know that a port can only be bound for listening once. So apparently I had another process on [...]

  4. [...] you have not read Part 1 of this Multi-Post tutorial, check it out now. This tutorial will rely on the code written in that [...]

  5. [...] you have not read Part 1 and Part 2 of this network tutorial series, please do so now. The code in this post will build upon [...]

Leave a Reply