[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip jnSocket.java, NONE, 1.1 socketLayer.java, NO
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-09-16 19:39:38
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32503/core/protocolsuite/tcp_ip Added Files: jnSocket.java socketLayer.java Log Message: Socket layer classes added. --- NEW FILE: jnSocket.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: socketLayer.java --- package core.protocolsuite.tcp_ip; import java.io.Serializable; import java.util.*; import core.CommunicationException; import core.LowLinkException; import core.LayerInfo; import core.Simulation; import core.TransportLayerException; import core.TransportLayerPortException; import core.InvalidNetworkLayerDeviceException; import core.protocolsuite.tcp_ip.ProtocolStack; /** * * @author key */ public class socketLayer { ProtocolStack mParentStack; private Vector sockTable = new Vector(); int lastSock; /** Creates a new instance of socketLayer */ public socketLayer(ProtocolStack inParentStack) { mParentStack= inParentStack; sockTable.clear(); lastSock = 0; } public int socket(short type, Application app){ sockTable.add(new jnSocket(lastSock, app, type)); lastSock++; return (lastSock - 1); } public jnSocket get_socket(int sock){ return (jnSocket)sockTable.get(sock); } public void bind(int sock, String srcIP, int srcPort) throws LowLinkException, TransportLayerException{ ((jnSocket)sockTable.get(sock)).src_IP = srcIP; //((jnSocket)sockTable.get(sock)).src_port = srcPort; <-- WRONG! //if(udp){ ((jnSocket)sockTable.get(sock)).open_state = true; //bind or connect or listen mParentStack.UDP().BindPort(sock, srcPort); //} //((jnSocket)sockTable.get(sock)).type // bind tcp or udp... } public void listen(int sock){ //if(tcp){ ((jnSocket)sockTable.get(sock)).open_state = true; //} } public void write(int sock, String msg){ //if() //tcp only write!!! } public void writeTo(int sock, String data, String IP, int port) throws LowLinkException, TransportLayerException{ // //if() // udp only write!!! ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; ((jnSocket)sockTable.get(sock)).open_state = true; mParentStack.UDP().sendUDPPacket(sock, IP, port, data); } public void recvFrom(int sock, String IP, int port, String data) throws LowLinkException, TransportLayerException{ if(sock < lastSock){ if(((jnSocket)sockTable.get(sock)).open_state == true){ //DEPRECATED IN SOON if(((jnSocket)sockTable.get(sock)).type != jnSocket.TCP_socket){ ((jnSocket)sockTable.get(sock)).dst_IP = IP; ((jnSocket)sockTable.get(sock)).dst_port = port; } //^^^^^^^^^^^^^^^^ //DEPRECATED IN SOON ((jnSocket)sockTable.get(sock)).app.RecvIP(IP); ((jnSocket)sockTable.get(sock)).app.RecvPrt(port); //^^^^^^^^^^^^^^^^ ((jnSocket)sockTable.get(sock)).app.RecvData(data); } } } public void close(int sock) throws TransportLayerException{ //((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; //if(udp){ mParentStack.UDP().ClosePort(sock); //else{ ((jnSocket)sockTable.get(sock)).src_port = 0; ((jnSocket)sockTable.get(sock)).src_IP = ""; } public void free(int sock) throws TransportLayerException{ ((jnSocket)sockTable.get(sock)).app = null; ((jnSocket)sockTable.get(sock)).open_state = false; } } |