Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Created December 27, 2015 20:01
Show Gist options
  • Save ryanmr/4c93cd542729be3d408b to your computer and use it in GitHub Desktop.
Save ryanmr/4c93cd542729be3d408b to your computer and use it in GitHub Desktop.

To compile:

javac NetworkApp.java

To run:

There are four CLI flags: 1: transport mode: tcp or udp 2: application mode: s or c (for client or server) 3: port number 4: server/hostname

Note: the SERVER end of the application must always be running FIRST.

TCP server:

java NetworkApp tcp s 9333

TCP client:

java NetworkApp tcp c 9333 localhost

UDP server:

java NetworkApp udp s 9333

UDP client:

java NetworkApp udp c 9333 localhost

There are five important methods. The first handles the CLI switches.

The other four, named according to their purpose, udp_client, udp_server, tcp_server, tcp_client. Each will run upon CLI argument (as noted above).

The TCP Client will run by created and then binding to a socket with host and port, and then send and recieve packets in a buffered form. The TCP Server will function the same, more or less. 10MB of bytes will be buffered and sent to the server from the client.

The UDP Client will first make 10 exchanges with the UDP Server (and if any fail, they will be repeated). Then, 10MB of bytes without the buffer will sent to the server from the client. On the client, after 5 seconds (to give the server time to catch up, if it needs it), the client will send application level termination signals to the server.

--

Sorry, the code's a mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment