tags:

views:

330

answers:

2

I have 2 windows PC's connected over an ad-hoc wlan network.
Using this existing connection can I communicate between these pc's via sockets?
Can I open a server socket on one pc and make the other pc a client and connect to the other pc and then send and receive data over this connection?
Do I need a specific api for this or can I just use java.net.Socket and java.net.ServerSocket?

+5  A: 

Of course you can. There is an IP network over the WLAN connection, and nothing stops you from establinshing TCP connection.

As far as sockets are concerned this is no different to a wired (Ethernet) connection, the difference ends at Data-Link layer

EFraim
+3  A: 

Of course you can use (Server)Sockets. Sockets are a concept of the TCP-protocol (OSI-layer 4), which operates on top of the IP-protocol (OSI-layer 3), which itself operates on top of WLAN or Ethernet (OSI-layer 2), which operates on a physical link (radio waves for WLAN, ethernet cables for ethernet).

The Implementations of the OSI-layers are replaceable (or better: should be replaceable). So it doesn't matter if you are using WLAN, ethernet or something else, as long as you don't go below layer 3 (which isn't possible with Java anyway).

Have a look at the Wikipedia article for more information

Hardcoded
Thanks to EFraim and you for the link, as I move up the OSI layer I see that layer 7 has HTTP there at application layer, it is a request /response protocol isn't it? Now is there some kind of push protocol like at that higher level or do I have to live with low level sockets at the moment.
Kevin Boyd
Java itself has only limted support for level 7 protocols. HTTP ist only the most common and is supported by Java directly. Java supports RMI, HTTP, FTP and JMX (may be incomplete). There are APIs which provide support for other protocols, like XMPP or serialization frameworks, like Google protocol buffers.A good starting point is Apache MINA or JBoss Netty. These are networking frameworks and there are some projects build upon them (like Vysper as XMPP Server).
Hardcoded